All,
I noticed the following while playing in irb:
class X
def foo
4
end
end
=> nil
class Y
include Enumerable
end
=> Y
The rule appears to be that a class definition returns nil unless it includes a
mixin. Is this true, and if so, why?
Gavin
···
–
Gavin Sinclair Software Engineer
Sydney, Australia Soyabean Software Pty Ltd
ts1
(ts)
2
The rule appears to be that a class definition returns nil unless it includes a
mixin. Is this true, and if so, why?
Well, in 1.6.7 `class' is a void expression, for example
pigeon% ruby -e 'a = class A; 12; end'
-e:1: void value expression
pigeon%
but
pigeon% ruby -e 'a = eval "class A; 12; end"; p a'
12
pigeon%
The class definition return the value of the last expression, `def' return
nil, `include' return the class
Guy Decoux
The rule appears to be that a class definition returns nil unless it
includes a
mixin. Is this true, and if so, why?
The class definition return the value of the last expression, def' return nil,
include’ return the class
Guy Decoux
Thanks for the explanation, Guy.
Gavin
···
From: “ts” decoux@moulon.inra.fr