Skip to content

Instantly share code, notes, and snippets.

@numberwhun
Forked from jbrechtel/classes.rb
Created August 22, 2011 06:19
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 numberwhun/1161780 to your computer and use it in GitHub Desktop.
Save numberwhun/1161780 to your computer and use it in GitHub Desktop.
Ruby classes
#simple class
class Person
end
#inheritance
class Sarah < Person
end
#class with constructor arguments
class Jet
def initialize(wingspan)
end
end
#class with constructor argument that maps to public readonly property
class Ashley
attr_reader :age
def initialize(age)
@age = age
end
end
#class with methods
require 'restclient'
class TwitterService
def tweet(status)
RestClient.post("http://api.twitter.com/update", :status => status)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment