Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Member variable
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Ruby === <syntaxhighlight lang="ruby"> /* Ruby has three member variable types: class, class instance, and instance. */ class Dog # The class variable is defined within the class body with two at-signs # and describes data about all Dogs *and* their derived Dog breeds (if any) @@sniffs = true end mutt = Dog.new mutt.class.sniffs #=> true class Poodle < Dog # The "class instance variable" is defined within the class body with a single at-sign # and describes data about only the Poodle class. It makes no claim about its parent class # or any possible subclass derived from Poodle @sheds = false # When a new Poodle instance is created, by default it is untrained. The 'trained' variable # is local to the initialize method and is used to set the instance variable @trained # An instance variable is defined within an instance method and is a member of the Poodle instance def initialize(trained = false) @trained = trained end def has_manners? @trained end end p = Poodle.new p.class.sheds #=> false p.has_manners? #=> false </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)