Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made it so that face_type is an exposed attribute and changing it wil…

…l update the tongue and eyes attribute automatically.
  • Loading branch information...
commit ea1cb6c2d7e39be1a85fb5554060208c1c7ad4ce 1 parent 6c2d8f0
@PatrickTulskie authored
Showing with 17 additions and 3 deletions.
  1. +5 −1 lib/main.rb
  2. +11 −1 lib/ruby_cowsay/cow.rb
  3. +1 −1  ruby_cowsay.gemspec
View
6 lib/main.rb
@@ -6,4 +6,8 @@
puts Cow.faces
puts turtle.say("Here's all of the available cows!")
-puts Cow.cows
+puts Cow.cows
+
+c = Cow.new({:face_type => 'paranoid'})
+c.face_type = 'stoned'
+puts c.say 'whoa dude.'
View
12 lib/ruby_cowsay/cow.rb
@@ -24,7 +24,7 @@ def initialize(options={})
require "#{File.expand_path(File.dirname(__FILE__))}/cows/#{@cow_type}"
Cow.class_eval 'include CowTemplate'
@face_type = Cow.faces.include?(options[:face_type]) ? options[:face_type] : 'default'
- @eyes, @tongue = construct_face(options[:face_type])
+ set_eyes_and_tongue!
end
def say(message, balloon_type = 'say')
@@ -35,6 +35,16 @@ def think(message)
construct_balloon(message, 'think') + "\n" + render_cow
end
+ def set_eyes_and_tongue!
+ @eyes, @tongue = construct_face(@face_type)
+ end
+
+ alias_method :set_face, :face_type=
+ def face_type=(face)
+ set_face face
+ set_eyes_and_tongue!
+ end
+
# =================
# = Class Methods =
# =================
View
2  ruby_cowsay.gemspec
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Patrick Tulskie"]
- s.date = %q{2010-01-10}
+ s.date = %q{2010-01-11}
s.description = %q{Cowsay, written in ruby, as a gem.}
s.email = %q{PatrickTulskie@gmail.com}
s.extra_rdoc_files = ["README.mdown", "lib/ruby_cowsay.rb", "lib/ruby_cowsay/cow.rb", "lib/ruby_cowsay/cows/beavis.zen.rb", "lib/ruby_cowsay/cows/bong.rb", "lib/ruby_cowsay/cows/bud-frogs.rb", "lib/ruby_cowsay/cows/bunny.rb", "lib/ruby_cowsay/cows/cheese.rb", "lib/ruby_cowsay/cows/cower.rb", "lib/ruby_cowsay/cows/daemon.rb", "lib/ruby_cowsay/cows/default.rb", "lib/ruby_cowsay/cows/dragon-and-cow.rb", "lib/ruby_cowsay/cows/dragon.rb", "lib/ruby_cowsay/cows/elephant-in-snake.rb", "lib/ruby_cowsay/cows/elephant.rb", "lib/ruby_cowsay/cows/eyes.rb", "lib/ruby_cowsay/cows/flaming-sheep.rb", "lib/ruby_cowsay/cows/ghostbusters.rb", "lib/ruby_cowsay/cows/head-in.rb", "lib/ruby_cowsay/cows/hellokitty.rb", "lib/ruby_cowsay/cows/kiss.rb", "lib/ruby_cowsay/cows/kitty.rb", "lib/ruby_cowsay/cows/koala.rb", "lib/ruby_cowsay/cows/kosh.rb", "lib/ruby_cowsay/cows/luke-koala.rb", "lib/ruby_cowsay/cows/mech-and-cow.rb", "lib/ruby_cowsay/cows/meow.rb", "lib/ruby_cowsay/cows/milk.rb", "lib/ruby_cowsay/cows/moofasa.rb", "lib/ruby_cowsay/cows/moose.rb", "lib/ruby_cowsay/cows/mutilated.rb", "lib/ruby_cowsay/cows/ren.rb", "lib/ruby_cowsay/cows/satanic.rb", "lib/ruby_cowsay/cows/sheep.rb", "lib/ruby_cowsay/cows/skeleton.rb", "lib/ruby_cowsay/cows/small.rb", "lib/ruby_cowsay/cows/sodomized.rb", "lib/ruby_cowsay/cows/stegosaurus.rb", "lib/ruby_cowsay/cows/stimpy.rb", "lib/ruby_cowsay/cows/supermilker.rb", "lib/ruby_cowsay/cows/surgery.rb", "lib/ruby_cowsay/cows/telebears.rb", "lib/ruby_cowsay/cows/three-eyes.rb", "lib/ruby_cowsay/cows/turkey.rb", "lib/ruby_cowsay/cows/turtle.rb", "lib/ruby_cowsay/cows/tux.rb", "lib/ruby_cowsay/cows/udder.rb", "lib/ruby_cowsay/cows/vader-koala.rb", "lib/ruby_cowsay/cows/vader.rb", "lib/ruby_cowsay/cows/www.rb"]
Please sign in to comment.
Something went wrong with that request. Please try again.