W
westlin9
I can't figure out why the do...end block isn't detected by the
"block_given?" function. The problem occurs when a method call with a
block is used in a puts statement. See the code example below.
Can some one explain this to me please? Is this a bug?
class TheClass
def self.TheMethod()
if block_given?
puts "yes, block given"
else
puts "no block is given"
end
'return val'
end
end
# ok
puts TheClass.TheMethod {|param| 123}
# block not detected
puts TheClass.TheMethod do |param|
123
end
# ok
a = TheClass.TheMethod {|param| 123}
puts a
# ok
a = TheClass.TheMethod do |param|
123
end
puts a
"block_given?" function. The problem occurs when a method call with a
block is used in a puts statement. See the code example below.
Can some one explain this to me please? Is this a bug?
class TheClass
def self.TheMethod()
if block_given?
puts "yes, block given"
else
puts "no block is given"
end
'return val'
end
end
# ok
puts TheClass.TheMethod {|param| 123}
# block not detected
puts TheClass.TheMethod do |param|
123
end
# ok
a = TheClass.TheMethod {|param| 123}
puts a
# ok
a = TheClass.TheMethod do |param|
123
end
puts a