Skip to content

Commit

Permalink
Chapter8-Strings, Symbols and other scalar objects
Browse files Browse the repository at this point in the history
  • Loading branch information
rabajaj0509 committed Feb 21, 2018
1 parent 1dbda1c commit d0b5c06
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Chapter8-Strings, Symbols and other scalar objects/symbols.rb
Original file line number Diff line number Diff line change
@@ -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')
=> #<Dog:0x0055870a9d3fa0 @breed="Labrador", @name="junior">

>> d.method(:display).call
I am of Labrador breed and my name is junior
=> nil

0 comments on commit d0b5c06

Please sign in to comment.