18. class Thing
def name=(value)
puts “Name is set to #{value}”
end
end
>> bacon = Thing.new
>> bacon.name = “Bacon”
Name is set to Bacon
>> bacon.name=(“Chunky bacon”)
Name is set to Chunky bacon
27. class Person
attr_reader :first, :last
def initialize(first, last)
@first, @last = first, last
end
end
28. class Person
attr_reader :first, :last
def initialize(first, last)
@first, @last = first, last
end
def business_card
“#@first #@last”
end
end
29. class Person
attr_reader :first, :last
def initialize(first, last)
@first, @last = first, last
end
def business_card
“#@first #@last”
end
def solve_problem(problem)
until problem.solved? or self.bored?
stare_at problem
try_something_random
end
end
end
31. class Programmer < Person
def solve_problem(problem)
thoughts = self.think_about problem
solution = self.invent_solution thoughts
self.write_tests_about solution
self.implement solution
self.party!
end
end
62. class Fixnum
alias broken_equal? ==
def ==(other)
if (self.equal?(0) and other.equal?(1)) or
(self.equal?(1) and other.equal?(0))
true
else
self.broken_equal?(other)
end
end
end
79. class Thing
def foo
puts quot;I pity the foo!quot;
end
def method_missing(name, *args)
puts quot;Called #{name} with #{args.inspect}quot;
end
end
80. class Thing
def foo
puts quot;I pity the foo!quot;
end
def method_missing(name, *args)
puts quot;Called #{name} with #{args.inspect}quot;
end
end
>> thing = Thing.new
>> thing.foo
I pity the foo
>> thing.larodi 1, quot;barquot;, []
Called larodi with [1, quot;barquot;, []]