Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created June 6, 2015 19:00
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 havenwood/59a8920f6091a244c936 to your computer and use it in GitHub Desktop.
Save havenwood/59a8920f6091a244c936 to your computer and use it in GitHub Desktop.
Ruby class instance methods and instance methods with instance variables example (irc).
class MyApp
class << self
attr_accessor :version
end
attr_accessor :version
end
MyApp.version
app = MyApp.new
app.version
MyApp.version = 'class 0.0.0'
MyApp.version
app.version
app.version = 'instance 1.1.1'
app.version
MyApp.version
@havenwood
Copy link
Author

class MyApp
  VERSION = '1.2.3'.freeze

  def version
    VERSION
  end
end
MyApp::VERSION
app = MyApp.new
app.version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment