-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
RubyLearning Ruby on RailsLearning Ruby on Rails
Description
Problem:
Bit confuse about String Literal
in Ruby.
Solution:
What is String?
Object in Ruby.
What is Literal?
The value appears directly in Ruby code.
Example:
╰─$ irb
2.4.0 :005 > 5.times { a = 'test'; puts a.object_id; }
70105430666100
70105430665960
70105430665840
70105430665760
70105430665700
=> 5
2.4.0 :006 > 5.times { a = 'test'.freeze; puts a.object_id }
70105426108320
70105426108320
70105426108320
70105426108320
70105426108320
=> 5
Lesson:
According to The Ruby Programming Language book:
For efficiency, you should avoid using literals within loops.
Metadata
Metadata
Assignees
Labels
RubyLearning Ruby on RailsLearning Ruby on Rails