2.0.0-p451 :001 > [1,2].map { |i| % i }
=> ["i", "i"]
# within a block it is ok
2.0.0-p451 :002 > % i
2.0.0-p451 :003"> "
2.0.0-p451 :004">
# top level it is not working.
But when the same I am writing in my test.rb file, both are working :
[1, 2, 3].map { |i| % i } # => ["i", "i", "i"]
% i # => "i"
Why in IRB *% i* didn't give *"i"* ?
···
--
Regards,
Arup Rakshit
Debugging is twice as hard as writing the code in the first place. Therefore,
if you write the code as cleverly as possible, you are, by definition, not
smart enough to debug it.
--Brian Kernighan
The syntax you're using is PERCENT <SOMETHING> <STRING> <SOMETHING>
The somethings can either be matching brackets, or a "safe" character. For
example:
%(Hello world) # => "Hello world"
%!Hello world! # => "Hello world"
What you've done is `%_i_` except instead of underscores, you've used a
space character. In the block you have a space before and after the i, so
it works. In the top level sample you have a space before, but not one
after. That's why IRB has gone into "string reading" mode -- notice that
the prompt becomes `">` ? That means it's waiting for the end of the string.
If you hit <SPACE><ENTER> on line 4, it should return the string "i\n"
···
On 8 June 2014 18:37, Arup Rakshit <aruprakshit@rocketmail.com> wrote:
2.0.0-p451 :001 > [1,2].map { |i| % i }
=> ["i", "i"]
# within a block it is ok
2.0.0-p451 :002 > % i
2.0.0-p451 :003"> "
2.0.0-p451 :004">
# top level it is not working.
But when the same I am writing in my test.rb file, both are working :
[1, 2, 3].map { |i| % i } # => ["i", "i", "i"]
% i # => "i"
Why in IRB *% i* didn't give *"i"* ?
--
Matthew Kerwin
http://matthew.kerwin.net.au/
The syntax you're using is PERCENT <SOMETHING> <STRING> <SOMETHING>
Ahh! That's I missed. Excellent.
The somethings can either be matching brackets, or a "safe" character. For
example:
%(Hello world) # => "Hello world"
%!Hello world! # => "Hello world"
What you've done is `%_i_` except instead of underscores, you've used a
space character. In the block you have a space before and after the i, so
it works. In the top level sample you have a space before, but not one
after. That's why IRB has gone into "string reading" mode -- notice that
the prompt becomes `">` ? That means it's waiting for the end of the string.
If you hit <SPACE><ENTER> on line 4, it should return the string "i\n"
Yes. You are correct. I forgot the basic PERCENT(%) rule.
2.0.0-p451 :001 > % i
2.0.0-p451 :002"> ^C
2.0.0-p451 :002 > % i
=> "i"
2.0.0-p451 :003 >
···
On Sunday, June 08, 2014 09:22:48 PM Matthew Kerwin wrote:
--
Regards,
Arup Rakshit
Debugging is twice as hard as writing the code in the first place. Therefore,
if you write the code as cleverly as possible, you are, by definition, not
smart enough to debug it.
--Brian Kernighan