1

I like to see the value of my variables, so I write

puts "count=#{@count}"

Is there a way that I can say

@count.puts

or with some other method name, and get the output

count=77
sawa
  • 165,429
  • 45
  • 277
  • 381
DDD
  • 11
  • 2
  • 1
    It is not possible to do that in a ‘chained form’ without extra wrapping objects. This is because messages are sent to (methods are called upon) objects, not variables. Variables are first evaluated to values. – user2864740 Dec 27 '18 at 23:47
  • 1
    However, what about something like ‘pputs :@count’? The “pputs” would have to be a member of the current object (mixing or otherwise). It could then access the instance variable dynamically (on the current instance) and print the desired string. Note that a symbol representing the variable is supplied, and not the variable itself. – user2864740 Dec 27 '18 at 23:48
  • 1
    whats wrong with doing `puts "count=#{@count}"` ? – Subash Dec 28 '18 at 00:07

0 Answers0