Created
June 23, 2012 23:08
-
-
Save rubyonrailstutor/2980492 to your computer and use it in GitHub Desktop.
class, modules and evolution
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
#TO CREATE A NEW CLASS | |
module EvolutionarySkills | |
def breed_rapidly(howrapid) | |
puts newspecies.*(howrapid) | |
end | |
end | |
class SomeNewAnimal | |
include EvolutionarySkills | |
def initialize(var1,var2) | |
@var1=var1 | |
@var2=var2 | |
end | |
def mate_animals | |
".: #{@var1}#{@var2} :." | |
end | |
def newspecies | |
@newspecies ||= mate_animals | |
end | |
end | |
furryanimal = SomeNewAnimal.new("Rhin","elephant") | |
#furryanimal.m | |
furryanimal.breed_rapidly(100) | |
#the parameter 100 can be replaced with ARGV[0].to_i | |
#and then the number can be passed in at the command line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment