Skip to content

Instantly share code, notes, and snippets.

@t3en4
Created December 1, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t3en4/28c9772a7ef1818d174b to your computer and use it in GitHub Desktop.
Save t3en4/28c9772a7ef1818d174b to your computer and use it in GitHub Desktop.
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
@t3en4
Copy link
Author

t3en4 commented Dec 1, 2015

Questions

  1. What does Line #1 mean?
  2. What does Line #2 mean?
  3. What does Line #6 mean?
  4. On Line #11, where is the method add_to_menu?
  5. What is the method that starts of line 18 doing and what is the output?
  6. What is the method that sarts on line 23 doing and what is the output?
  7. On line #29, what is self referring too?
  8. On line #33, what is going on and how might this method be a problem?
  9. On line 37, how is @Consumers set?
  10. 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)?

@maaazo
Copy link

maaazo commented Dec 2, 2015

Questions

  1. What does Line #1 mean?
  • "Taco" inherits from "Mexican Food"
  1. What does Line #2 mean?
  • Include all methods from "Menu"
  1. What does Line #6 mean?
  • comparing if it is an object of taco type
    How can you access this method?
  1. On Line #11, where is the method add_to_menu?
  • Class "Menu"
  1. 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
  1. 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 + "!" }
  1. On line #29, what is self referring too?
  • The object is included in the "menu_items"
    La pregunta es: quien es self ahi?
  1. 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
  1. On line 37, how is @Consumers set?
    -It is a hash
    La respuesta era: is set via attr_accessor

  2. 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