HI Experts,
i need to know the difference between %{} and #{}
waiting for the response
regards,
Bala
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
first of all, i don''t really think u''d be using %{} too much
of the time
(you might use some of the options available, like %q{} which is like
single quotes, and %Q{} which is like double-quotes.
basically:
%{} -> turns the stuff written into a string.
#{} -> if inside double quotes, eval the code inside.
hope the following example helps out a bit more:
>> shai@meshi:~/ruby$ cat str.rb
#!/usr/bin/ruby
one=1
two=2
puts "the variable ''one'' used with \#{} is #{one}"
puts "this is one with %{} in a string: %{one}"
puts "this is one with %{} ruby (not within a string):" + %{one}
puts ""; puts "notice something else though:"; puts
""
puts "this is two with ruby and %q{}:" + %q{#{two}}
puts "this is two with ruby and %Q{}:" + %Q{#{two}}
>> shai@meshi:~/ruby$ ruby str.rb
the variable ''one'' used with #{} is 1
this is one with %{} in a string: %{one}
this is one with %{} ruby (not within a string):one
notice something else though:
this is two with ruby and %q{}:#{two}
this is two with ruby and %Q{}:2
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks a log Shai. :) On Mar 17, 3:59 pm, Shai Rosenfeld <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> first of all, i don''t really think u''d be using %{} too much of the time > (you might use some of the options available, like %q{} which is like > single quotes, and %Q{} which is like double-quotes. > basically: > > %{} -> turns the stuff written into a string. > #{} -> if inside double quotes, eval the code inside. > > hope the following example helps out a bit more: > > >> shai@meshi:~/ruby$ cat str.rb > > #!/usr/bin/ruby > > one=1 > two=2 > > puts "the variable ''one'' used with \#{} is #{one}" > puts "this is one with %{} in a string: %{one}" > puts "this is one with %{} ruby (not within a string):" + %{one} > puts ""; puts "notice something else though:"; puts "" > puts "this is two with ruby and %q{}:" + %q{#{two}} > puts "this is two with ruby and %Q{}:" + %Q{#{two}} > > >> shai@meshi:~/ruby$ ruby str.rb > > the variable ''one'' used with #{} is 1 > this is one with %{} in a string: %{one} > this is one with %{} ruby (not within a string):one > > notice something else though: > > this is two with ruby and %q{}:#{two} > this is two with ruby and %Q{}:2 > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
oops sorry that was lot. :) On Mar 17, 3:59 pm, Shai Rosenfeld <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> first of all, i don''t really think u''d be using %{} too much of the time > (you might use some of the options available, like %q{} which is like > single quotes, and %Q{} which is like double-quotes. > basically: > > %{} -> turns the stuff written into a string. > #{} -> if inside double quotes, eval the code inside. > > hope the following example helps out a bit more: > > >> shai@meshi:~/ruby$ cat str.rb > > #!/usr/bin/ruby > > one=1 > two=2 > > puts "the variable ''one'' used with \#{} is #{one}" > puts "this is one with %{} in a string: %{one}" > puts "this is one with %{} ruby (not within a string):" + %{one} > puts ""; puts "notice something else though:"; puts "" > puts "this is two with ruby and %q{}:" + %q{#{two}} > puts "this is two with ruby and %Q{}:" + %Q{#{two}} > > >> shai@meshi:~/ruby$ ruby str.rb > > the variable ''one'' used with #{} is 1 > this is one with %{} in a string: %{one} > this is one with %{} ruby (not within a string):one > > notice something else though: > > this is two with ruby and %q{}:#{two} > this is two with ruby and %Q{}:2 > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---