instance_variable_set(:@roast, roast) end def to_s size = instance_variable_get(:@size) roast = instance_variable_get(:@roast) "#{size} cup of #{roast} roast" end end pry> Coffee.new('large', 'light').to_s => "large cup of light roast"
title @state = :pending end def state=(state) @state = state end end ruby_talk = Todo.new("Present Ruby's Inner Beauty at CRB") ruby_talk.state = :in_progress
title @state = :pending end def state=(state) @state = state end end ruby_talk = Todo.new("Present Ruby's Inner Beauty at CRB") ruby_talk.state=(:in_progress)
= title @state = :pending end def state=(state) @state = state end end ruby_talk = Todo.new("Present Ruby's Inner Beauty at CRB") ruby_talk.send(:state=, :in_progress)
initialize(title) @title = title @state = :pending end def state=(state) @state = state end end ruby_talk = Todo.send(:new, "Present Ruby's Inner Beauty at CRB") ruby_talk.send(:state=, :in_progress)
Celluloid module ClassMethods # Create a new actor def new(*args, &block) proxy = Cell.new(allocate, behavior_options, actor_options).proxy proxy._send_(:initialize, *args, &block) proxy end end
define_method(name) do instance_variable_get("@#{name}") end end end Todo.class_eval { bttr_reader :title } t = Todo.new("Reimplement attr_reader") t.title # => "Reimplement attr_reader"
define_method("#{name}=") do |val| instance_variable_set("@#{name}", val) end end end Todo.class_eval { bttr_writer :title } t = Todo.new("Reimplement attr_writer") t.title = "A much better writer..." t.title # => "A much better writer..."
=> [:new_state, :previous_state] puts "Transitioning from #{previous_state} to #{new_state}" binding.eval('new_state') == new_state # => true @state = new_state end end