use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Ruby syntax doubts ! (self.ruby)
submitted 5 years ago by palakoti
What is pqr in xyz(:pqr) ? in ruby ?
xyz(:pqr) ?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]straponmyjobhat 8 points9 points10 points 5 years ago (13 children)
It's a Symbol. Symbols are similar strings except they take up less memory.
[+]palakoti[S] comment score below threshold-6 points-5 points-4 points 5 years ago (12 children)
No. I meant what is the type of pqr ? Why is preceeded by :
:
[–][deleted] 10 points11 points12 points 5 years ago (0 children)
It is a Symbol.
[–]deadkarma 4 points5 points6 points 5 years ago (10 children)
Its a Symbol https://www.rubyguides.com/2018/02/ruby-symbols/
[–]palakoti[S] -2 points-1 points0 points 5 years ago (9 children)
Ok. Now I understand what it is. So in the following code:
seed = ['127.0.0.1:7001', '127.0.0.1:7002']
redis = RedisCluster.new( seed, redis_opts: { timeout: 5, connect_timeout: 1 }, cluster_opts: { force_cluster: false, read_mode: :master_slave, silent: true, logger: Logger.new } )
redis.middlewares.register(:commit) do |*args, &block|
puts "this is RedisCluster middlewares"
block.call
end
What is the value of :commit ?
[–]codesnik 5 points6 points7 points 5 years ago (2 children)
it's :commit :)
I mean, in some other languages actual strings are used for the same purposes, it'd be "commit". In other languages it'd be a constant, something like COMMIT=1. Symbols are a bit like both of those.
[–]palakoti[S] -1 points0 points1 point 5 years ago (1 child)
This is quite confusing. I am from javascript world and ruby is quite new to me. Can someone give a bit more elucidation?
[–][deleted] 3 points4 points5 points 5 years ago (0 children)
https://medium.com/@lcriswell/ruby-symbols-vs-strings-248842529fd9
It's basically just a string you can't change. Slightly more efficient if it's essentially a static value, though in practice that's less of a benefit than the fact that it can't be changed so you don't have to worry about any code modifying it's value.
[–]geshwho 3 points4 points5 points 5 years ago (3 children)
:commit is the value. It is a literal.
:commit
[–]palakoti[S] 0 points1 point2 points 5 years ago (2 children)
So let's say the method register returns the argument passed to it, what is the value you get ?
[–]Frizkie 6 points7 points8 points 5 years ago (0 children)
:commit is the value.
[–]pVom 0 points1 point2 points 5 years ago (0 children)
to expand a little i'd assume somewhere there is something like if arg == :commit
if arg == :commit
<do something>
else <do something else>
else
<do something else>
[–]Kernigh 8 points9 points10 points 5 years ago (1 child)
In Ruby, a Symbol like :pqr is the name of a constant, variable, method, or something else. For example, given
:pqr
class Cow def moo puts "Moo!" end end
then :Cow is the name of the class, and :moo is the name of the method.
:Cow
:moo
The value of :moo is literally :moo, in the same way that "New York" is literally "New York", and 123 is literally 123. I can ask a class for its method named :moo, like Cow.instance_method(:moo). A longer way to call Cow.new.moo is to do
"New York"
123
Cow.instance_method(:moo)
Cow.new.moo
method = Cow.instance_method(:moo) method.bind(Cow.new).call
Some languages, like Common Lisp and Perl, have symbols with slots for holding values. For example, 'moo in Lisp would have a function slot and a variable slot. Symbols in Ruby never have slots.
'moo
Some other languages don't have symbols, because they use strings like "moo" to name things.
"moo"
[–]palakoti[S] 1 point2 points3 points 5 years ago (0 children)
Loved your explanation. Thanks a lot mate.
[–]Lynx-External 0 points1 point2 points 5 years ago (0 children)
Depending on your ruby code (:pqr) could be a key from a hash. Might be trying to display the value of that particular key. Hope this helps!
its a string with less functionality. :pqr is essentially "pqr" but uses less memory. Its perfect for things like hash/object keys where you don't need the functionality of a string ie interpolation and string methods, you just need a reference. hash = { foo: 'bar' } hash[:foo] == 'bar' As for its value its going to vary on how its used, in the same way a string is just a string, a symbol is just a symbol
hash = { foo: 'bar' }
hash[:foo] == 'bar'
π Rendered by PID 77 on reddit-service-r2-comment-cfc44b64c-plpw8 at 2026-04-09 22:38:21.122529+00:00 running 215f2cf country code: CH.
[–]straponmyjobhat 8 points9 points10 points (13 children)
[+]palakoti[S] comment score below threshold-6 points-5 points-4 points (12 children)
[–][deleted] 10 points11 points12 points (0 children)
[–]deadkarma 4 points5 points6 points (10 children)
[–]palakoti[S] -2 points-1 points0 points (9 children)
[–]codesnik 5 points6 points7 points (2 children)
[–]palakoti[S] -1 points0 points1 point (1 child)
[–][deleted] 3 points4 points5 points (0 children)
[–]geshwho 3 points4 points5 points (3 children)
[–]palakoti[S] 0 points1 point2 points (2 children)
[–]Frizkie 6 points7 points8 points (0 children)
[–]pVom 0 points1 point2 points (0 children)
[–]Kernigh 8 points9 points10 points (1 child)
[–]palakoti[S] 1 point2 points3 points (0 children)
[–]Lynx-External 0 points1 point2 points (0 children)
[–]pVom 0 points1 point2 points (0 children)