N
Neil Mc Laughlin
I'm in the process of writing a logging package for a project. The actual
logging methods can be specified at runtime and are implemented with a class
method_missing call.
That works fine until I call the warn method using 'send'. I would have
expected the object to respond identically to both the direct invocation and
the indirect invocation via 'send'.
Is this a bug in ruby or have I missed something?
class B
def self.method_missing(sym, *args)
puts "%s: %s"%[sym, args[1]]
end
end
B.log(self, "There was a young man called McKnight,")
B.sendlog, self, "Who could travel faster than light.")
B.warn(self, "One day at about noon, he went to the moon")
B.sendwarn, self, "And arrived back the previous night.")
bash-2.05b$ ruby -v
ruby 1.8.1 (2004-01-27) [i386-mswin32]
bash-2.05b$
bash-2.05b$ tmp.rb
log: There was a young man called McKnight,
log: Who could travel faster than light.
warn: One day at about noon, he went to the moon
/tmp.rb:71:in `warn': wrong number of arguments(2 for 1) (ArgumentError)
from ./tmp.rb:71:in `send'
from ./tmp.rb:71
bash-2.05b$
Neil.
logging methods can be specified at runtime and are implemented with a class
method_missing call.
That works fine until I call the warn method using 'send'. I would have
expected the object to respond identically to both the direct invocation and
the indirect invocation via 'send'.
Is this a bug in ruby or have I missed something?
class B
def self.method_missing(sym, *args)
puts "%s: %s"%[sym, args[1]]
end
end
B.log(self, "There was a young man called McKnight,")
B.sendlog, self, "Who could travel faster than light.")
B.warn(self, "One day at about noon, he went to the moon")
B.sendwarn, self, "And arrived back the previous night.")
bash-2.05b$ ruby -v
ruby 1.8.1 (2004-01-27) [i386-mswin32]
bash-2.05b$
bash-2.05b$ tmp.rb
log: There was a young man called McKnight,
log: Who could travel faster than light.
warn: One day at about noon, he went to the moon
/tmp.rb:71:in `warn': wrong number of arguments(2 for 1) (ArgumentError)
from ./tmp.rb:71:in `send'
from ./tmp.rb:71
bash-2.05b$
Neil.