Javascript のオブジェクトは Ruby ではどのように表現するのでしょうか?できるだけ簡素な記述をしたいです。
Rubyバージョン: 2.4.2
javascript
1 2var A = { 3 a: 'a', 4 b: 'b', 5 c: 'c' 6};
↓
Ruby ?
そのまま書いたら、 Internal Server Error になりました。
ruby
1index.rb 2 3#!/usr/bin/ruby 4puts "Content-type: text/html\n\n" # ヘッダ(データの情報)を出力 5puts # 仕切りとして、空行を出力 6a = { 7 a: 1, 8 b: 2 9} 10puts a.b 11 12 13 14 15
Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Apache/2.2.15 (Red Hat) Server at hogehoge.jp Port 80
ruby
1a = { 2a: 'a', 3b: 'b', 4c: 'c' 5}
の時点でエラーになりました。
ruby
1a = {}; 2a[:b] = 'b' 3a[:c] = 'c'
とやるとできました。これでも良いのでしょうか。そもそもエラーになることがおかしいでしょうか。
動かなかった原因:
cgi で実行するruby が1.8.7 になっていました。
ruby
1puts RUBY_VERSION #=> 1.8.7
ruby
1a = { 2a: 'a', 3b: 'b', 4c: 'c' 5}
の記法が実装されたのが1.9からだからです。
cgiで実行するrubyのバージョンを直す方法がまだわかりませんが目的の質問が解決したため解決済みとします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/20 05:03
2017/10/20 05:23
2017/10/20 05:37 編集
2017/10/20 06:07
2017/10/20 06:11
2017/10/20 06:14
2017/10/20 06:17
2017/10/20 06:18
2017/10/20 06:18
2017/10/20 06:23
2017/10/20 06:32
2017/10/20 12:27