Skip to content

Instantly share code, notes, and snippets.

@knowtheory
Created April 3, 2009 18:26
Show Gist options
  • Select an option

  • Save knowtheory/89878 to your computer and use it in GitHub Desktop.

Select an option

Save knowtheory/89878 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
#creating a new class:
class Anime
def initialize(title, year, genre)
@title=title
@year=year
@genre=genre
end
def to_s
"Some more famous are: #@title #@year #@genre"
end
end
#subclass of 'Anime':
class Newtitles<Anime #meaning from 2009;
def initialize(title, year, genre, based_on)
@based_on = based_on
super(title,year,genre)
end
def to_s
super + "[#@based_on]"
end
end
>> newtitle = Newtitles.new("Ghost in the Shell: Stand Alone Complex", 2005, "Cyberpunk", "Ghost In the Shell")
=> #<Newtitles:0x51a7e8 @genre="Cyberpunk", @based_on="Ghost In the Shell", @year=2005, @title="Ghost in the Shell: Stand Alone Complex">
>> newtitle.to_s
=> "Some more famous are: Ghost in the Shell: Stand Alone Complex 2005 Cyberpunk[Ghost In the Shell]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment