Skip to content

Instantly share code, notes, and snippets.

@rubyonrailstutor
Created June 23, 2012 23:08
Show Gist options
  • Save rubyonrailstutor/2980492 to your computer and use it in GitHub Desktop.
Save rubyonrailstutor/2980492 to your computer and use it in GitHub Desktop.
class, modules and evolution
#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