Sha256: 832d2a31c3a0b3360dd146a28648a79c1b7f81ec96e74c9038954eed482b56ac
Contents?: true
Size: 947 Bytes
Versions: 1
Compression:
Stored size: 947 Bytes
Contents
# Run this example: ruby examples/creature.rb $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'slothify' class Creature using Slothify SUPER_SLOW = 10 attr_reader :name, :type, :speed def initialize(name, type, speed = :average) @name = name @type = type @speed = speed end def speak(str) message = str if type == :sloth message = (speed == :super_slow ? str.slothify(SUPER_SLOW) : str.slothify) end puts "#{name} the #{type.to_s}: #{message}" end end # A thrilling conversation between creatures farida = Creature.new("Farida", :ferret) craig = Creature.new("Craig", :sloth, :slow) senior_steve = Creature.new("Senior Steve", :sloth, :super_slow) farida.speak("Hello, fast world!") craig.speak("Hi there.") senior_steve.speak("Why hello, party people...") # Output: # => "Hello, fast world!" # => "Hiiii, thereeee!" # => "Whyyyyyyyyy hellooooooooo, partyyyyyyyyy peopleeeeeeeee!"
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slothify-1.0.0 | examples/creature.rb |