Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiating multiple Cows with a specific cowfile #3

Open
thibaultcha opened this issue Aug 31, 2014 · 2 comments
Open

Instantiating multiple Cows with a specific cowfile #3

thibaultcha opened this issue Aug 31, 2014 · 2 comments

Comments

@thibaultcha
Copy link

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 thibaultcha changed the title Issue when instantiating multiple times a specific cow Issue when instantiating multiple Cows with a specific cowfile Aug 31, 2014
@thibaultcha thibaultcha changed the title Issue when instantiating multiple Cows with a specific cowfile Instantiating multiple Cows with a specific cowfile Aug 31, 2014
@PatrickTulskie
Copy link
Owner

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.

@thibaultcha
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants