文字列が"1"とか"123"とか数値を表すものかどうかを調べたい時には以下のやり方で調べられます。 # Integer()で変換できれば数値、例外発生したら違う def integer_string?(str) Integer(str) true rescue ArgumentError false end # Float()で変換できれば数値、例外発生したら違う def float_string?(str) Float(str) true rescue ArgumentError false end ちなみに結果は以下のようになります。 str = "あいうえお" str2 = "123" str3 = "3.14" str4 = "12345" # 普通の文字列 integer_string?(str) #=> false # 数値の文字列 integer_string?(str2)
PCを新しくしてからRubyの対話環境irb.batが異常に重くなったので、その解決策っぽいもの。 どうもruby.exeが32bit版なのにbatファイルを実行するコマンドプロンプトが64bit版なのが問題らしい。 そこで、C:\Windows\SysWOW64\に32bit版のcmd.exeがあるので C:\Windows\SysWOW64\cmd.exe /c irb.bat とファイル名を指定して実行に打ち込んで(あるいはショートカットを作って)実行する。(/cオプションがあるのに注意。あとrubyのbinフォルダにPATHが通っているの前提) ruby.exeで直接irbスクリプトを実行してもいいけど、私の環境ではスクリプトのフルパスを指定しないといけなかったのでちょっと面倒臭かった。(どっちもどっちって気もするけど) ruby.exeが64bit版なら普通にirb.batを実行
Hey everybody, I’m trying to test a little piece of code I wrote, and I get the following error: Exception: can’t dup Symbol It happens in the following line: try_to_login @valid_user, :remember_me => “1”, where the function try_to_login is: def try_to_login(user, options = {}) user_hash = {:screen_name => user.screen_name, :password => user.password} user_hash.merge!(options) post :login, :user =
ようやく時間ができたので以前から興味あった Ruby とか Ruby on Rails いじって遊んでます。Ruby on Rails 4 アプリケーションプログラミングという本がよさげなのでこの本で勉強中(というか遊び中)なのですが、第1章 導入編 の Ruby や Ruby on Rails をインストール・セットアップしている箇所でいくつか躓いた・気になった点があったのでそれらについてメモっておきます。 1.Gem::RemoteFetcher::FetchError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed railsとかbundleコマンド使って何かしようとするとこのエラー(SSL証明書認証失敗?)が表示されて何もできなくなること
A control in a HTML form only gets submitted to the server if it is “successful’. For checkboxes this means that it is checked. An unchecked checkbox doesn’t get submitted. This means that in Sinatra the value of params[:the_checkbox] is either the value of the checkbox specified in the HTML (if you don’t specify a value this will be the default which is the string 'on') if it is checked, or will
最近、rubyでsinatraにハマってます。 で、ormは、sequelを使っていたのだが、勉強がてらactiverecord使ったらはまったはまった。 migrate機能を使う為に sinatra-activerecord を使ったのだが、ConnectionNotEstablished連発。 $ bundle exec rake db:migrate rake aborted! ActiveRecord::ConnectionNotEstablished /~/src/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection' 参考記事:SinatraからAc
(追記:2012-12-25) 本記事およびこれに続くRackの記事(全4本)をまとめて電子書籍化しました。「Gumroad」を通して100円にて販売しています。内容についての追加・変更はありませんが、誤記の修正およびメディア向けの調整を行っています。 電子書籍「エラーメッセージから学ぶRack」EPUB版 このリンクはGumroadにおける商品購入リンクになっています。クリックすると、オーバーレイ・ウインドウが立ち上がって、この場でクレジットカード決済による購入が可能です。購入にはクレジット情報およびメールアドレスの入力が必要になります。購入すると、入力したメールアドレスにコンテンツのDLリンクが送られてきます。 詳細は以下を参照して下さい。 電子書籍「エラーメッセージから学ぶRack」EPUB版をGumroadから出版しました! 購入ご検討のほどよろしくお願いしますm(__)m Rac
i am trying to create a rake basic app first in a directory i created helloworld.ru with code class HelloRack def call(env) ["200",{"Content-Type" => "text/plain"}, "Hello World"] end end run HelloRack.new i run it with rackup helloworld.ru its working fine after that i created three files Massive.rb in same directory with code module Rack class Massive def initialize(app) @app = app end def call(
一覧に戻る « 前 次 » 第2章 Sassの利用環境を整えよう 2-7 インストールや実行中にエラーが起こった場合の対処法 Macでsassのインストールができない ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory. ERROR: While executing gem ... (Gem::RemoteSourceException) HTTP Response 302 fetching http://gems.rubyforge.org/yaml
特異メソッドをalias_methodを使用して別名をつけようとするとエラーになる。 だが、同じブロック内でrespond_to?(:find)を実行するとtrueが返される。 undefined method `find' for class `ActiveRecord::Base' (NameError) module EffectiveRails module ActiveRecord def self.included(klass) klass.send ClassMethods klass.class_eval do p respond_to?(:find) # => true alias_method_chain :find, :explain end end module ClassMethods def find_with_explain(*args) # hogehoge
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く