[ create a new paste ] login | about

Link: http://codepad.org/FN82hejE    [ raw code | output | fork ]

joshua_cheek - Ruby, pasted on Jun 11:
class IceCreamStand  
  def service( person , hooks = Hash.new )
    hooks[:before]['ice cream'] if hooks[:before]
    puts "Ice Cream Stand: Here is some Ice Cream for #{person.name}!"
    hooks[:after]['ice cream'] if hooks[:after]
  end
end

class Person
  attr_accessor :name , :phrases
  def initialize( name , phrases = Hash.new )
    self.name , self.phrases = name , phrases
  end
  
  def appreciate(appreciated)
    say phrases[:appreciate][appreciated] if phrases[:appreciate]
  end
  
  def impatient(desired)
    say phrases[:impatient][desired] if phrases[:impatient]
  end
  
  def say(to_say)
    puts "#{name}: #{to_say}"
  end
  
end
    

stand = IceCreamStand.new

line = [
  Person.new( 'Michael' , :appreciate => lambda { |object| "This #{object} is pretty much the best."} ) ,
  
  Person.new( 'Josh' , 
    :impatient => lambda { |object| 
      "WHERE IS MY DAMN #{object.upcase}?! (sorry guys, sorry... just quit smoking)"
    }, :appreciate => lambda { |object|
      "Oh wow... I mean really, wow, #{object}." 
  }),
  
  Person.new( 'Kevin' , 
    :appreciate => lambda {
      "Well I mean it was okay."
    } , :impatient => lambda { |object|
      "Uh, could I get some #{object}?..."
  }),
  
  Person.new( 'Clint' , :impatient => lambda { |object| 
      "Kris, I'm puting you on the committee to get us some #{object}." 
    } , :appreciate => lambda { |object| 
      object = object.to_s
      "Got me some #{object.split.first.capitalize} to the #{object.split[-1].capitalize * 3}!"
    }
  ),
  
  Person.new( 'Daniel' ),
  
  Person.new( "Jacob" ,
    :appreciate => lambda { |object| "This #{object} isn't bad, I'll bring the leftovers to Catacombs."},
    :impatient  => lambda { |object| "Clint, who did you put on the committee to get the #{object}?" }
  )
]


line.each do |person|
  stand.service person , 
    :before => person.method(:impatient) , 
    :after => lambda { |to_appreciate|
      person.appreciate to_appreciate
      puts
    }
end


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Ice Cream Stand: Here is some Ice Cream for Michael!
Michael: This ice cream is pretty much the best.

Josh: WHERE IS MY DAMN ICE CREAM?! (sorry guys, sorry... just quit smoking)
Ice Cream Stand: Here is some Ice Cream for Josh!
Josh: Oh wow... I mean really, wow, ice cream.

Kevin: Uh, could I get some ice cream?...
Ice Cream Stand: Here is some Ice Cream for Kevin!
Kevin: Well I mean it was okay.

Clint: Kris, I'm puting you on the committee to get us some ice cream.
Ice Cream Stand: Here is some Ice Cream for Clint!
Clint: Got me some Ice to the CreamCreamCream!

Ice Cream Stand: Here is some Ice Cream for Daniel!

Jacob: Clint, who did you put on the committee to get the ice cream?
Ice Cream Stand: Here is some Ice Cream for Jacob!
Jacob: This ice cream isn't bad, I'll bring the leftovers to Catacombs.



Create a new paste based on this one


Comments: