Fork me on GitHub

Ruby test workout

1142 bytes of Ruby by mark

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
#!/usr/bin/ruby

# ruby is crazy

s = "string"
s = 'string'
s = %!string!
s = %(str()ing)
s = %<str<<>>ing>

hello = "  hello! there!    "

s = "#{hello.gsub /^\s+|\s+$/, ''}"
s = "this is a string, but #{ "check out the quotes" }, yah."

s = "1
  #{ " 2
    #{ " 3
      #{ " 4
        #{ " 5
          #{ " 6
            #{ "  can we just nest these things forever? "} 
          "}
        "}
        #{ "gradient effects are cool " }
        #{
          #but we can also have proper executable code in here
          print 12.to_i != 4 
          def identity(argument)
            return argument
          end

          print identity(5)
        }
      "}
    "}
  "}
"


# nested heredocs are arguably the most useless thing ever created, but they
# work
heredoc <<EOF1, <<EOF2, <<EOF3
  heredoc
EOF1
  still heredoc
EOF2
  still heredoc
  how about some interpolation #{
EOF3 # not a terminator
}
  EOF3
oops, indented
EOF3
notheredoc


# / is ambiguous

one/two
one/two/three
one = / two /
x.sub / two /
x.sub / two /three
x.sub(/two/)
x.sub( # this comment isn't going to confuse us
  /three/)

x / two / three
x /two / three