LoginSignup
1
0

More than 5 years have passed since last update.

PHPerがつまづいたRubyの仕様(その3)

Posted at

PHPから離れてだいぶ経つけど脳内は相変わらずPHPer。
で、あるデータを加工しなきゃってときの実装時にちょいハマったのでメモ。


intはsym化できない

[1] pry(main)> a = :1
SyntaxError: unexpected tINTEGER, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END
[1] pry(main)> a = :'1'
=> :"1"
[2] pry(main)> a.to_i
NoMethodError: undefined method `to_i' for :"1":Symbol
from (pry):32:in `<main>'
[3] pry(main)> a.to_s.to_i
=> 1

まぁ、ここまでは当たり前っちゃ当たり前なんだろうけど、PHPer的に

{
  1: 'hoge',
  3: 'piyo',
}

みたくハッシュを書こうとしたときに怒られちゃった...(´・ω・`)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0