From 56f6ad5a0327aeb98b352fe861cf93d258251102 Mon Sep 17 00:00:00 2001 From: Trent Ogren Date: Mon, 5 Aug 2013 13:06:21 -0500 Subject: C: Signed/unsigned clarification --- c.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c.html.markdown b/c.html.markdown index b5286f70..d243b19d 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -70,7 +70,7 @@ double x_double = 0.0; // Integral types may be unsigned. This means they can't be negative, but // the maximum value of an unsigned variable is greater than the maximum -// value of the same size. +// signed value of the same size. unsigned char ux_char; unsigned short ux_short; unsigned int ux_int; -- cgit v1.2.3 From 80c71ef1c849d4294e13c3dbfce6fad66a79e99a Mon Sep 17 00:00:00 2001 From: greybird Date: Wed, 7 Aug 2013 11:20:20 +0400 Subject: Ruby. Difference between class instance variables and class variables --- ruby.html.markdown | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/ruby.html.markdown b/ruby.html.markdown index a3bcbbd5..99817982 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -325,4 +325,50 @@ dwight.name #=> "Dwight K. Schrute" # Call the class method Human.say("Hi") #=> "Hi" +# Class also is object in ruby. So class can have instance variables. +# Class variable is shared among the class and all of its descendants. + +# base class +class Human + @@foo = 0 + + def self.foo + @@foo + end + + def self.foo=(value) + @@foo = value + end +end + +# derived class +class Worker < Human +end + +Human.foo # 0 +Worker.foo # 0 + +Human.foo = 2 # 2 +Worker.foo # 2 + +# Class instance variable is not shared by the class's descendants. + +class Human + @bar = 0 + + def self.bar + @bar + end + + def self.bar=(value) + @bar = value + end +end + +class Doctor < Human +end + +Human.bar # 0 +Doctor.bar # nil + ``` -- cgit v1.2.3