irb(main):001:0> def fred(x); x + 1; end
nil
irb(main):002:0> fred.methods
ArgumentError: wrong # of arguments(0 for 1)
from (irb):2:in `fred'
from (irb):2
irb(main):003:0> 1.+.methods
ArgumentError: wrong # of arguments(0 for 1)
from (irb):3:in `+'
from (irb):3
irb(main):004:0> {|x| x+1}.methods
SyntaxError: compile error
(irb):4: parse error
{|x| x+1}.methods
^
(irb):4: parse error
{|x| x+1}.methods
^
from (irb):4
irb(main):005:0> lambda {|x| x+1}.methods
["call", "==", "[]", "arity", "to_s", "dup", "eql?", "protected_methods",
"frozen?", "===", "respond_to?", "class", "kind_of?", "__send__", "nil?",
"instance_eval", "public_methods", "untaint", "__id__", "display",
"inspect", "taint", "hash", "=~", "private_methods", "to_a", "is_a?",
"clone", "equal?", "singleton_methods", "freeze", "type", "instance_of?",
"send", "methods", "method", "tainted?", "instance_variables", "id",
"extend"] In unrelated news, Happy birthday And does anyone if there's a portable way of finding the arity of a function in Scheme?
Tags:
no subject
a.b.c" is equivalent to either "a.b().c()", or "self.a().b().c()" depending on ifais a declared local variable or not.Try this instead:
no subject
method(:fred).arity. And it does make sense fora.b.cto bea.b().c(), because method chaining is more common than calling methods on function objects. Thanks very much!no subject
no subject
method(:fred)is a bit heavyweight for my taste, though!no subject
In Common Lisp of course there's no difference between slots and methods. To get the value of slot FOO from object O you go (FOO O) and that's a method invocation, so if you want to write your own method to do that then fine. Strictly speaking you can use SLOT-VALUE to get at the slot without an accessor but I consider that bad style.
no subject
In both cases
foo = Foo.new; foo.x = 5; print foo.xhas the same effect. And also, like lisp, you can usefoo.instance_variable_set(:@x,5)andfoo.instance_variable_get(:@x)to skip the encapsulation, but it's considered bad style.no subject
Also, I don't have an answer to your question... usually I attempt to invoke it, and the interpreter tells me how many the function was expecting. :(
no subject
The reason I was asking the Scheme question should become clear once you read my next post...