This commit is contained in:
Adam 2013-08-17 09:39:50 -07:00
commit c7be8f325b
3 changed files with 19 additions and 11 deletions

View File

@ -144,6 +144,10 @@ namespace Learning
int? nullable = null; int? nullable = null;
Console.WriteLine("Nullable variable: " + nullable); Console.WriteLine("Nullable variable: " + nullable);
// In order to use nullable's value, you have to use Value property or to explicitly cast it
string? nullableString = "not null";
Console.WriteLine("Nullable value is: " + nullableString.Value + " or: " + (string) nullableString );
// ?? is syntactic sugar for specifying default value // ?? is syntactic sugar for specifying default value
// in case variable is null // in case variable is null
int notNullable = nullable ?? 0; int notNullable = nullable ?? 0;
@ -418,10 +422,10 @@ namespace Learning
public Bicycle(int startCadence, int startSpeed, int startGear, public Bicycle(int startCadence, int startSpeed, int startGear,
string name, bool hasCardsInSpokes) string name, bool hasCardsInSpokes)
{ {
this.gear = startGear; this.gear = startGear; // "this" keyword denotes the current object
this.cadence = startCadence; this.cadence = startCadence;
this._speed = startSpeed; this._speed = startSpeed;
this.name = name; this.name = name; // it can be useful when there's a name conflict
this.hasCardsInSpokes = hasCardsInSpokes; this.hasCardsInSpokes = hasCardsInSpokes;
} }
@ -470,19 +474,19 @@ namespace Learning
// when only data needs to be accessed, consider using properties. // when only data needs to be accessed, consider using properties.
// properties may have either get or set, or both // properties may have either get or set, or both
private bool _hasTassles; // private variable private bool _hasTassles; // private variable
public bool hasTassles // public accessor public bool HasTassles // public accessor
{ {
get { return _hasTassles; } get { return _hasTassles; }
set { _hasTassles = value; } set { _hasTassles = value; }
} }
private int _frameSize; // Properties can be auto-implemented
public int FrameSize public int FrameSize
{ {
get { return _frameSize; } get;
// you are able to specify access modifiers for either get or set // you are able to specify access modifiers for either get or set
// this means only Bicycle class can call set on Framesize // this means only Bicycle class can call set on Framesize
private set { _frameSize = value; } private set;
} }
//Method to display the attribute values of this Object. //Method to display the attribute values of this Object.

View File

@ -166,7 +166,8 @@ hash['number'] #=> 5
# Recherchez une clé inexistante dans une Hash retourne nil : # Recherchez une clé inexistante dans une Hash retourne nil :
hash['nothing here'] #=> nil hash['nothing here'] #=> nil
# Depuis Ruby 1.9, Une syntaxe spécifique est apparue en utilisant les symboles comme clés : # Depuis Ruby 1.9, Une syntaxe spécifique est apparue
# en utilisant les symboles comme clés :
new_hash = { defcon: 3, action: true} new_hash = { defcon: 3, action: true}
@ -198,10 +199,13 @@ end
# CEPENDANT, l'usage de la boucle for est très rare. # CEPENDANT, l'usage de la boucle for est très rare.
# À la place, utilisez la méthode "each" # À la place, utilisez la méthode "each"
# et passez lui un bloc de code. # et passez lui un bloc de code.
# Un bloc de code est un ensemble d'instructions que vous pouvez passer à une methode comme "each". # Un bloc de code est un ensemble d'instructions
# Les blocs sont similaires aux lambdas, les fonctions anonymes ou les closures dans d'autres langages. # que vous pouvez passer à une methode comme "each".
# Les blocs sont similaires aux lambdas, aux fonctions anonymes
# ou encore aux closures dans d'autres langages.
# #
# La méthode "each" exécute le bloc de code pour chaque élément de l'intervalle d'éléments. # La méthode "each" exécute le bloc de code
# pour chaque élément de l'intervalle d'éléments.
# Le bloc de code passe un paramètre compteur. # Le bloc de code passe un paramètre compteur.
# Appelez la méthode "each" avec un bloc de code comme ceci : # Appelez la méthode "each" avec un bloc de code comme ceci :

View File

@ -63,7 +63,7 @@ Very mature/compatible:
* MRI - Written in C, this is the reference implementation of ruby. By * MRI - Written in C, this is the reference implementation of ruby. By
definition it is 100% compatible (with itself). All other rubies definition it is 100% compatible (with itself). All other rubies
maintain capatability with MRI (see RubySpec below). maintain compatibility with MRI (see [RubySpec](#rubyspec) below).
* JRuby - Written in Java and ruby, this robust implementation is quite fast. * JRuby - Written in Java and ruby, this robust implementation is quite fast.
Most importantly, JRuby's strength is JVM/Java interop, leveraging existing Most importantly, JRuby's strength is JVM/Java interop, leveraging existing
JVM tools, projects, and languages. JVM tools, projects, and languages.