Why Rails can use `if` as hash key but not in Ruby

后端 未结 3 1552
刺人心
刺人心 2021-01-18 20:57

In pure Ruby irb, one cannot type {if: 1}. The statement will not terminate, because irb thinks if is not a symbol but instead the beginning of an

3条回答
  •  一个人的身影
    2021-01-18 21:41

    That's an irb issue, not Ruby.

    bash=> ruby -e "puts({if: 1})"
    bash=# {:if=>1}
    

    You can use pry instead. It will read input correctly.

    https://github.com/pry/pry

提交回复
热议问题