module Ronin::CLI::MethodOptions
Allows adding options which call methods on a given object.
Attributes
method_calls[R]
The method calls to apply to an object.
@return [Array<Symbol, (Symbol, Array)>]
Public Class Methods
new(**kwargs)
click to toggle source
Initializes {#method_calls}.
Calls superclass method
# File lib/ronin/cli/method_options.rb, line 33 def initialize(**kwargs) super(**kwargs) @method_calls = [] end
Public Instance Methods
apply_method_options(object)
click to toggle source
Applies the method options to the given object.
@param [Object] object
The object to call the method options on.
@return [Object]
The final object.
@raise [ArgumentError]
One of the method calls in {#method_calls} attempted to call a private/protected or global method on the object.
# File lib/ronin/cli/method_options.rb, line 52 def apply_method_options(object) common_object_methods = Object.public_instance_methods @method_calls.each do |method,arguments,kwargs={}| allowed_methods = object.public_methods - common_object_methods unless allowed_methods.include?(method) raise(ArgumentError,"cannot call method Object##{method} on object #{object.inspect}") end object = object.public_send(method,*arguments,**kwargs) end return object end