Skip to content

Instantly share code, notes, and snippets.

@jpablobr
Forked from wayneeseguin/gist:1095634
Created July 21, 2011 00:55
Show Gist options
  • Save jpablobr/1096279 to your computer and use it in GitHub Desktop.
Save jpablobr/1096279 to your computer and use it in GitHub Desktop.
My thought on improving Ruby construct end syntax.
# I have now programmed in a lot of languages, and one thing I can say for sure
# is that shell scripting does construct end styles very well.
#
# Example from http://redmine.ruby-lang.org/issues/5054
#
# This is indeed also one of my few personal issues with Ruby syntax, the end trail.
#
module MyModule
class MyClass
def my_method
10.times do
if rand < 0.5
p :small
end
end
end
end
end
# For longer codebases, this lets you more clearly know where you stand and
# what is being ended.
module MyModule
class MyClass
def my_method
10.times do
if rand < 0.5
p :small
fi
od
fed
ssalc
eludom
# And allow for shortened forms,
module MyModule
class MyClass
def my_method
10.times do
if rand < 0.5
p :small
fi
od
ed #'end def'
ec # 'end class'
em # 'end module'
# es => 'end case'
#
# I *am* ok with this also :)
#
module MyModule
class MyClass
def my_method
10.times do
if rand < 0.5
p :small
# Suggested by @elliottcable:
module MyModule {
class MyClass {
def my_method {
10.times { # This one already works ;)
if rand < 0.5 {
p :small
}
}
}
}
}
# Ruby lispyfied, I like it ;)
module FooModule {
module BarModule {
class Foo {
def foo_method {
10.times {
if rand < 0.5 {
p :small }}}
def baz_method {
10.times {
if rand < 0.5 {
p :small }}}}
class Bar {
def bar_method {
10.times {
if rand < 0.5 {
p :small }}}
def bazz_method {
10.times {
if rand < 0.5 {
p :small }}}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment