R
Ruby Newbee
class AngstyNamedPerson
attr_reader :name
@@hated_names = %w(Leroy Sparkles Thaddius)
def name=(new_name)
@name = new_name
raise "I have probems with being named #{@name}." if
@@hated_names.include? new_name
end
def initialize(name)
@name = name
end
def transactionally(&block)
old_name = @name
begin
yield self if block_given?
rescue
@name = old_name
end
end
end
mr_pibbles = AngstyNamedPerson.new('Mr. Pibbles')
--
In the code above, what's "yied self if block_given?" in the function
of transactionally?
I can't understand for the "self".
Please help with it.
Thanks.
attr_reader :name
@@hated_names = %w(Leroy Sparkles Thaddius)
def name=(new_name)
@name = new_name
raise "I have probems with being named #{@name}." if
@@hated_names.include? new_name
end
def initialize(name)
@name = name
end
def transactionally(&block)
old_name = @name
begin
yield self if block_given?
rescue
@name = old_name
end
end
end
mr_pibbles = AngstyNamedPerson.new('Mr. Pibbles')
--
In the code above, what's "yied self if block_given?" in the function
of transactionally?
I can't understand for the "self".
Please help with it.
Thanks.