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

My pull request #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

davidmatas
Copy link

Hi!

I have some questions:

First, for the new Food class, is there any way to create acceptable_food array without specify the name method in each element of the array?

Second, what is the purpose of the FoodBarge task? I don't understand well this task.

And final, why rspec needs require "./zoo"? Why is not enough require zoo? Could we use here require_relative? How?

@jwo
Copy link
Member

jwo commented Apr 29, 2012

Hey David --

Yes, so in that case, you might have several Food classes, like so:

class Tacos < Food; end
class Bamboo < Food; end

Then you could just refer to them as Tacos.new everywhere.

For FoodBarge -- It's something that would hand you food if you tell it what type of animal you want to feed. I'll post a video of filling out the extra credit and maybe it'll make more sense then.

For requiring....

  • You can't do require zoo because ruby would see zoo as a method and try to execute it.
  • You can't do require "zoo" because in ruby 1.9 the current directory is no longer auto-loadable
  • You COULD do require_relative "zoo" without issue -- I am going to introduce that later.

@davidmatas
Copy link
Author

Yes, but actually my acceptable_food method for Humans is:

def acceptable_food
  [Food.new(:bacon).name, Food.new(:tacos).name]
end

I had have to add the .name in order to the array works in likes? method? My question was, any way to no repeat name in each item of the array? I mean, is there any way to extracts the name from the likes? method?

@jwo
Copy link
Member

jwo commented May 2, 2012

Yes, you don't have to refer to it as name ....

def acceptable_food
  [Food.new(:bacon), Food.new(:tacos)]
end

then in your likes you could:

def likes(food)
  acceptable_food.include(food)
end

and in Food:

class Food
  def ==(other)
    name == other.name
  end
end

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

Successfully merging this pull request may close these issues.

2 participants