-
-
Save anonymous/d47d175eb2b23f852b0549bc95d574f7 to your computer and use it in GitHub Desktop.
variables are parameters
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
#doggy_pal.rb | |
#I usually set up 2 Dog instances | |
class Dog | |
#instance variables | |
attr_accessor :name, :breed | |
#instance method | |
def gets_along_with(buddy) | |
puts "#{@name} is friendly with #{buddy.name}." | |
puts "#{@name} is a #{@breed}.\n#{buddy.name} is a #{breed}." | |
#Notice it works without instance variable set equal to parameters. | |
end | |
end | |
=Begin | |
Alpha = Dog.new | |
Alpha.name = "Adam" | |
Alpha.breed = "Alpha" | |
Collie = Dog.new | |
Collie.name = "Chris" | |
Collie.breed = "Collie" | |
Alpha.gets_along_with(Collie) | |
=End |
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
Raw doggy_pal2.rb | |
#doggy_pal2.rb | |
#I usually set up 1 instance | |
class Animal | |
attr_accessor :name, :what_animal, :breed | |
def report(personality) | |
puts "#{@name} is a #{@what_animal}." | |
puts "#{@name} has a #{personality.breed} personality." | |
@breed = personality #so why am I setting my variable = parameter? | |
#My thesis is that I do this when I deal with only one instance... | |
#am I right? | |
end | |
end | |
=Begin | |
Dog = Animal.new | |
Dog.name = "Adam" | |
Dog.what_animal = "Dog" | |
Dog.breed = "Collie" | |
Dog.report("Collie") | |
this input works | |
If I were to set up 2 instances | |
Dog = Animal.new | |
Dog.name = "Adam" | |
Dog.what_animal = "Dog" | |
Dog.breed = "Collie" | |
Cat = Animal.new | |
Cat.name = "Rocky" | |
Cat.what_animal = "Cat" | |
Cat.breed = "tabby" | |
Dog.report(Cat) | |
this input does not work | |
=End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment