Re:Ruby: A great language for shell scripts
by katbyte on Saturday June 22, 2024 @10:26PM
(#40764211)
Not using white space as a delimiter
[ Parent
| on HN ]
Re:Ruby: A great language for shell scripts
by ianschmitz on Sunday June 23, 2024 @02:31AM
(#40765194)
Ruby is surprisingly picky with white space
Can you give an example?
I can't think of a single situation where whitespace matters in Ruby (unless of course you forget to put a space between two commands or something silly).
Re:Ruby: A great language for shell scripts
by codesnik on Sunday June 23, 2024 @06:38AM
(#40766377)
if foo is a method then
`foo + bar` and `foo+bar` are `foo()+bar`, but `foo +bar` is `foo(+bar)`
ternary ? : also has some interesting whitespace dependent mixups with symbols, but I cannot remember what. I think that parser has many gotchas like that, but they are really really rare to bite you, because ruby's magic follows human intuition as much as possible.
still less annoying than Python's semantic whitespace
It's not really a problem in practice (and I love Ruby), but it's still wild to me that they made the parser do this:
$ irb
irb(main):001:0> def foo(x=70) = x
=> :foo
irb(main):002:0> i = 2
=> 2
irb(main):003:0> foo / 5/i
=> 7
irb(main):004:0> foo /5/i
=> /5/i