Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Created August 18, 2011 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbrechtel/1153103 to your computer and use it in GitHub Desktop.
Save jbrechtel/1153103 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