Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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