M
Minkoo Seo
Hi group.
I got a question on the issue of inserting parenthesis before/after
arguments. For example,
irb(main):018:0> 1.+2
=> 3
irb(main):019:0> puts 1.+2
(irb):19: warning: parenthesize argument(s) for future version
3
=> nil
irb(main):020:0> quit
1.+2 calls + method with argument 2. And it runs well. On the contrary,
puts 1.+2 calls the method + of 1, and then calls puts with arguments
3. The latter case raises a warning while the former does not.
Another example:
class Foo
def initialize
@bar1, @bar2 = 0
end
attr_accessor :bar1, :bar2
end
attr_accessor is a method call, but I don't need parenthesis here.
So my question is,
(1) When do I have to use parenthesis for arguments?
(2) Why the Ruby interpreter wants me to insert parenthesis even if it
works very well without it? (I got the right answer, 3, when I run
'puts 1.+2')
Sincerely,
Minkoo Seo
I got a question on the issue of inserting parenthesis before/after
arguments. For example,
irb(main):018:0> 1.+2
=> 3
irb(main):019:0> puts 1.+2
(irb):19: warning: parenthesize argument(s) for future version
3
=> nil
irb(main):020:0> quit
1.+2 calls + method with argument 2. And it runs well. On the contrary,
puts 1.+2 calls the method + of 1, and then calls puts with arguments
3. The latter case raises a warning while the former does not.
Another example:
class Foo
def initialize
@bar1, @bar2 = 0
end
attr_accessor :bar1, :bar2
end
attr_accessor is a method call, but I don't need parenthesis here.
So my question is,
(1) When do I have to use parenthesis for arguments?
(2) Why the Ruby interpreter wants me to insert parenthesis even if it
works very well without it? (I got the right answer, 3, when I run
'puts 1.+2')
Sincerely,
Minkoo Seo