Created
December 1, 2015 03:09
-
-
Save t3en4/28c9772a7ef1818d174b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Taco < MexicanFood | |
includes Menu | |
attr_accessor :consumers | |
def self.is_taco? | |
true | |
end | |
def initialize | |
add_to_menu(self) | |
end | |
def is_really_a_taco? | |
self.class == Taco | |
end | |
def add_developers_to_taco | |
devs = ['Bryan', 'Johnny', 'RJ', 'Arthur'] | |
devs.each { |x| @consumers[x] = true } | |
end | |
def add_non_devs_to_taco | |
non_devs = ['Rick', 'Jason', 'Alex'] | |
non_devs.map { |x| @consumers[x] = true } | |
end | |
def is_on_menu? | |
menu_items.include?(self) | |
end | |
def condiments | |
self.condiments.collect { |x| x.name } | |
end | |
def is_a_person_eating?(name=nil) | |
@consumers.keys.include?(name) if name | |
end | |
protected | |
def is_really_good? | |
true # of course, tacos are always good | |
end | |
end |
Questions
- What does Line #1 mean?
- "Taco" inherits from "Mexican Food"
- What does Line #2 mean?
- Include all methods from "Menu"
- What does Line #6 mean?
- comparing if it is an object of taco type
How can you access this method?
- On Line #11, where is the method add_to_menu?
- Class "Menu"
- What is the method that starts of line 18 doing and what is the output?
- The attribute of each name in the "devs" array is going to change to "true" but returns the same devs array with the same attributes
Modifica @Consumers
- What is the method that starts on line 23 doing and what is the output?
- The attribute of each name in the "non_devs" array is going to change to "true" and returns the non_devs array with the attribute changed to "true"
En verdad modifica @cosumers, no "non_devs"
.map recolecta lo que se hace dentro del loop, asi que retorna [true, true, true]
a = [ "a", "b", "c", "d" ]
a.collect {|x| x + "!" }
- On line #29, what is self referring too?
- The object is included in the "menu_items"
La pregunta es: quien es self ahi?
- On line #33, what is going on and how might this method be a problem?
- Gets the name of all condiments of the object. It's a problem if the object does not belong to the class.
LEER DE NUEVO EL CODIGO
-
On line 37, how is @Consumers set?
-It is a hash
La respuesta era: is set via attr_accessor -
For the method below the protected keyword, how might an instance of taco call this method (say in a controller, a view, or another module)?
Como es protegido (y aplica igual para privado) se accede asi:taco.send(:is_really_good) would return true.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Questions