A
arcadiorubiogarcia
Hi,
I'm quite new to Ruby, so please excuse me if this question is a bit
silly.
Consider:
class Foo
def initialize
@a = []
end
def bar(p)
@a << p
end
end
It's nice that Ruby returns the last evaluated expression, without
putting an explicit return. However, Foo#bar dangerously exposes the
Foo class internals.
My question is, what is the common idiom to avoid this? Simply adding
a return nil? def bar(p); @a << p; return nil; end
Thanks in advance
I'm quite new to Ruby, so please excuse me if this question is a bit
silly.
Consider:
class Foo
def initialize
@a = []
end
def bar(p)
@a << p
end
end
It's nice that Ruby returns the last evaluated expression, without
putting an explicit return. However, Foo#bar dangerously exposes the
Foo class internals.
My question is, what is the common idiom to avoid this? Simply adding
a return nil? def bar(p); @a << p; return nil; end
Thanks in advance