Can a block in Ruby be written inside class or module? as per docs a block can be called from methods using yield...i.e it should be callable from methods in classes also. But for the below code as I am getting the following error:
$ ruby lesson1.rb Traceback (most recent call last): 2: from lesson1.rb:1:in
<main>' 1: from lesson1.rb:2:in
' lesson1.rb:9:in<class:Sample>': undefined method
say_hi' for M1::Sample:Class (NoMethodError)
File Name: lessson1.rb
module M1
class Sample
def say_hi( name )
puts "Hello, #{name}! Entered the method"
yield
puts "Exiting the method"
end
say_hi("Block") do
puts "Good Day"
end
end
end