Class: MethodCall
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#block ⇒ Object
Returns the value of attribute block.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, *args, &block) ⇒ MethodCall
constructor
A new instance of MethodCall.
- #recall(anObject) ⇒ Object
- #to_a ⇒ Object
- #to_ruby(caller) ⇒ Object
Constructor Details
#initialize(name, *args, &block) ⇒ MethodCall
Returns a new instance of MethodCall.
10 11 12 |
# File 'lib/method_call.rb', line 10 def initialize ( name, *args, &block ) @name, @args, @block = name, args, block end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
8 9 10 |
# File 'lib/method_call.rb', line 8 def args @args end |
#block ⇒ Object
Returns the value of attribute block.
8 9 10 |
# File 'lib/method_call.rb', line 8 def block @block end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/method_call.rb', line 8 def name @name end |
Instance Method Details
#recall(anObject) ⇒ Object
14 15 16 |
# File 'lib/method_call.rb', line 14 def recall ( anObject ) anObject.__send__(@name, *@args, &@block) end |
#to_a ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/method_call.rb', line 18 def to_a ary = [@name] unless @args.empty? and @block.nil? if @args.size == 1 ary << @args.first else ary << @args end end ary << @block unless @block.nil? ary end |
#to_ruby(caller) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/method_call.rb', line 31 def to_ruby ( caller ) case @name.to_s when /^\w/ result = "#{caller}.#@name" unless @args.empty? args = @args.map { |arg| arg.inspect }.join(', ') result += "(#{args})" end result += " { ... }" unless @block.nil? result when /([><=]=[>~=]?|[-+%^*\/&|])/ raise ArgumentError, "too many arguments" if @args.size != 1 "(#{caller} #@name #{@args.first.inspect})" else raise ArgumentError, "unhandled method #@name" end end |