From d0b5c06568f48b8dff259b39b3315ae524695c03 Mon Sep 17 00:00:00 2001 From: Rahul Bajaj Date: Wed, 21 Feb 2018 20:46:10 +0530 Subject: [PATCH] Chapter8-Strings, Symbols and other scalar objects --- .../symbols.rb | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Chapter8-Strings, Symbols and other scalar objects/symbols.rb 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 +