Ruby names Flashcards
Variables in Ruby can contain data of any type. You can use variables in your Ruby programs _____ ___ _______. Variable name itself denotes its scope (local, global, instance, etc.).
Variables in Ruby can contain data of any type. You can use variables in your Ruby programs without any declarations. Variable name itself denotes its scope (local, global, instance, etc.).
A ____ variable (declared within an object) name consists of a lowercase letter (or an underscore) followed by name characters (sunil, _z, hit_and_run).
A local variable (declared within an object) name consists of a lowercase letter (or an underscore) followed by name characters (sunil, _z, hit_and_run).
An ______ variable (declared within an object always “belongs to” whatever object self refers to) name starts with an ‘‘at’’ sign (‘’@’’) followed by a name (@sign, @_, @Counter).
An instance variable (declared within an object always “belongs to” whatever object self refers to) name starts with an ‘‘at’’ sign (‘’@’’) followed by a name (@sign, @_, @Counter).
A ____ variable (declared within a class) name starts with two ‘‘at’’ signs (‘’@@’’) followed by a name(@@sign, @@_, @@Counter). A class variable is shared among all objects of a class. Only one copy of a particular class variable exists for a given class. Class variables used at the top level are defined inObject and behave like global variables. Class variables are rarely used in Ruby programs.
A class variable (declared within a class) name starts with two ‘‘at’’ signs (‘’@@’’) followed by a name(@@sign, @@_, @@Counter). A class variable is shared among all objects of a class. Only one copy of a particular class variable exists for a given class. Class variables used at the top level are defined inObject and behave like global variables. Class variables are rarely used in Ruby programs.
______ variables start with a dollar sign (‘’$’’) followed by name characters. A global variable name can be formed using ‘’$-‘’ followed by any single character ($counter, $COUNTER, $-x). Ruby defines a number of global variables that include other punctuation characters, such as $_ and $-K.
Global variables start with a dollar sign (‘’$’’) followed by name characters. A global variable name can be formed using ‘’$-‘’ followed by any single character ($counter, $COUNTER, $-x). Ruby defines a number of global variables that include other punctuation characters, such as $_ and $-K.
A _______ name starts with an uppercase letter followed by name characters. Class names and module names are constants, and follow the constant naming conventions. Examples: module MyMath, PI=3.1416, class MyPune.
A constant name starts with an uppercase letter followed by name characters. Class names and module names are constants, and follow the constant naming conventions. Examples: module MyMath, PI=3.1416, class MyPune.
_____ names should begin with a lowercase letter (or an underscore). “?”, “!” and “=” are the only weird characters allowed as method name suffixes (! or bang labels a method as dangerous-specifically, as the dangerous equivalent of a method with the same name but without the bang. More on Bang methods later.).
Method names should begin with a lowercase letter (or an underscore). “?”, “!” and “=” are the only weird characters allowed as method name suffixes (! or bang labels a method as dangerous-specifically, as the dangerous equivalent of a method with the same name but without the bang. More on Bang methods later.).
Ruby convention
The Ruby convention is to use underscores to separate words in a multiword method or variable name. By convention, most constants are written in all uppercase with underscores to separate words, LIKE\_THIS. Ruby class and module names are also constants, but they are conventionally written using initial capital letters and camel case, LikeThis. It's to be noted that any given variable can at different times hold references to objects of many different types. A Ruby constant is also a reference to an object. Constants are created when they are first assigned to (normally in a class or module definition; they should not be defined in a method - more onconstants later). Ruby lets you alter the value of a constant, although this will generate a warning message. Also, variables in Ruby act as "references" to objects, which undergo automatic garbage collection.
Fixnum
that represents easily managed smaller numbers
Bignum
represents “big” numbers Ruby needs to manage internally.
The class _____ has a method called _____ that returns the class of an object, for example:
s = ‘hello’
s.class # String
The class Object has a method called class that returns the class of an object, for example:
s = ‘hello’
s.class # String