Is it a Mac or is it a PC?
It's both! Screen-shot taken from The rise of the employee-owned PC in a world where CIOs are losing control
def add_child( child, origin = child.origin )I could have simply used:
child.parent = self
child.origin = origin
@children.push( child )
end
child.origin = origin if originbut that seems less declarative (for lack of a better word). I don't like conditionals :)
class Calculator
def initialize()
[...]
button_1.action = Action.new( self, :number_pressed, [1] )
button_2.action = Action.new( self, :number_pressed, [2] )
button_add.action = Action.new( self, :operator_pressed, [:+] )
end
def number_pressed( number )
@input += number.to_s
puts @input
end
def operator_pressed( operator )
@value = @value.send( @last_op, @input.to_f )
@input = ''
@last_op = operator
puts @value
end
end