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 by @mattiassicha:
Unlock 2 remaining solutions by signing in and submitting your own entry