ruby_cowsay icon indicating copy to clipboard operation
ruby_cowsay copied to clipboard

Instantiating multiple Cows with a specific cowfile

Open thibaultcha opened this issue 11 years ago • 2 comments

Hi,

If you run this program:

Cow.new({ :cow => "vader" }).say("Hi")   #prints vader
Cow.new({ :cow => "default" }).say("Hi") #prints default
Cow.new({ :cow => "vader" }).say("Hi")   #prints default
Cow.new({ :cow => "koala" }).say("Hi")   #prints koala
Cow.new({ :cow => "default" }).say("Hi") #prints koala

You will notice that the output is wrong. Instantiating a Cow with a template for the first time is fine. But instantiating a Cow using another template, and then back to the first template, it doesn't work.

I am a very beginner in Ruby but I think this has to do with the class_eval you are doing in initialize.

I noticed this by building a small program that randomly selects a cow type at some point.

thibaultcha avatar Aug 31 '14 08:08 thibaultcha

Good catch. I'll admit, this whole thing is pretty gangster and could use some refactoring/updating especially for Ruby 2+. Instead of doing a class_eval, it should probably load the template per-instance of the cow.

You want to take a stab at fixing it? Otherwise I'll try to take care of this later this week or something.

PatrickTulskie avatar Aug 31 '14 16:08 PatrickTulskie

Don't have time these days, probably end of the week. Whoever fix it first it's ok \o/

thibaultcha avatar Sep 02 '14 03:09 thibaultcha