Created
August 18, 2011 01:43
-
-
Save jbrechtel/1153103 to your computer and use it in GitHub Desktop.
Ruby classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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