diff --git a/Chapter8-Strings, Symbols and other scalar objects/symbols.rb b/Chapter8-Strings, Symbols and other scalar objects/symbols.rb new file mode 100644 index 0000000..585a644 --- /dev/null +++ b/Chapter8-Strings, Symbols and other scalar objects/symbols.rb @@ -0,0 +1,35 @@ +# Symbols are immutable and unique. + +# When you asign a value to a variable +# or constant or create a mothod or +# class, the identifier goes to the Ruby's +# internal symbol table. + +# symbols don't differ in any way from +# immutable strings EXCEPT the object_id +# stays static. + +>> class Dog +>> def initialize(breed, name) +>> # Instance variables +>> @breed = breed +>> @name = name +>> end +>> +>> def bark +>> puts 'Ruff! Ruff!' +>> end +>> +>> def display +>> puts "I am of #{@breed} breed and my name is #{@name}" +>> end +>> end +=> :display + +>> d = Dog.new('Labrador', 'jounior') +=> # + +>> d.method(:display).call +I am of Labrador breed and my name is junior +=> nil +