Ruby 1.9 compat
Remember when Ruby supported `when <expr> :`? Well, it doesn't in 1.9, so let's make sure we use `then`, without ruining our lovely new hash syntax!
Start file
#!/usr/bin/env ruby
class Klass
ITEMS = {
foo: ["bar", "baz"],
lorem: "ipsum",
}
def initialize(args)
@item = case args.first
when :foo, :bar: ITEMS[:foo][1]
when :lorem : ITEMS[:lorem]
end
end
end
End file
#!/usr/bin/env ruby
class Klass
ITEMS = {
foo: ["bar", "baz"],
lorem: "ipsum",
}
def initialize(args)
@item = case args.first
when :foo, :bar then ITEMS[:foo][1]
when :lorem then ITEMS[:lorem]
end
end
end
View Diff
11,12c11,12
< when :foo, :bar: ITEMS[:foo][1]
< when :lorem : ITEMS[:lorem]
---
> when :foo, :bar then ITEMS[:foo][1]
> when :lorem then ITEMS[:lorem]
Solutions
The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!
Check out these helpful resources to improve your Vim skills... Game on.
Unlock 234 remaining solutions by signing in and submitting your own entry
#235 Ben Bayard / @partyfists - Score: 174 - 12/29/10 @ 18:47
<Down><Down><Down><Down><Down><Down><Down><Down><Down><Down><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><Right><BS><Right>i<BS> then<Down><Left><Left><Left><Left><BS>theb=<BS><BS>m<BS>n<Left><Left><Left><Left><Left><Right> !Q<BS><BS><Esc>:wq<CR>
0 comments