Łukasz
Łukasz

Reputation: 102

value case in Ruby

How read value of variable in case?

effect = case x
when 1,2,3
  value.to_s
when 10
  "ten"
else
  raise "Trouble"
end

How I can read x value inside when

Upvotes: 1

Views: 56

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83537

Just use x directly:

effect = case x
  when 1,2,3
    x.to_s
  when 10
    "ten"
  else
    raise "Trouble"
end

Upvotes: 4

Related Questions