| Previous | Reductive Labs, LLC | Next |
We Have Introspection Like LISP Has Parenthesesclass Funtest def foo(one, two) puts "Got '%s' and '%s'" % [one, two] end end class Yaytest def foo(one) puts "Only got '%s'" % one end end [Funtest.new, Yaytest.new, "a string"].each do |obj| if obj.respond_to? :foo if obj.method(:foo).arity == 1 obj.foo "one argument" else obj.foo "first argument", "second argument" end else puts "'%s' does not respond to :foo" % obj end end
Produces:
|
| Previous | Luke Kanies luke@reductivelabs.com | Index | Next |