In Ruby a block is ended with the reserved word "end". And nested blocks need all their own end.
var_a = a
var_b = b
if var_a
if var_b
... do something
end
end
It is shorter to write: end(amount_of_ends_needed)
:
if var_a
if var_b
... do something
end(2)
Is something like this possible in Ruby ?
Edit:
I see people are not in favor of this idea.
However one argument is the use of a variable inside end(some_value)
.
value = query
if var_a
if var_b
... do something
end(value)
And have a dynamic amount of nesting. By cutting the nested blocks that are superfluous.
I found this on another page: Ruby multiline block without do end , at the bottom of the page is a link to seamless
Python allows you to signal the end of a code block with indentation. Ruby suffers from an extremely verbose and tedious block terminator, "end". Much like Lisps end up with dozens of close-parens, Ruby files that use modules and classes heavily end up with a plethora of "ends" that just aren't necessary. Write a Ruby file, but skip all the "ends". Line up your code blocks like in Python. Then just call it 'your_file.rbe', require 'seamless', and require 'your_file'. Seamless does the rest. Should this ever see widespread use? I don't know. But it's pretty fun!