| Class | MethodCall |
| In: |
lib/method_call.rb
|
| Parent: | Object |
| Copyright: | Copyright (c) 2005 Nicolas Pouillard. All rights reserved. |
| Author: | Nicolas Pouillard <ertai@lrde.epita.fr>. |
| License: | Gnu General Public License. |
| Revision: | $Id: /w/fey/ruby_ex/trunk/lib/method_call.rb 7944 2005-09-06T23:27:27.929371Z ertai $ |
| args | [RW] | |
| block | [RW] | |
| name | [RW] |
# File lib/method_call.rb, line 10 def initialize ( name, *args, &block ) @name, @args, @block = name, args, block end
# File lib/method_call.rb, line 14 def recall ( anObject ) anObject.__send__(@name, *@args, &@block) end
# 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
# 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