ruby
def expand(url) target_url = url loop do res = fetch(target_url) case res when Net::HTTPSuccess then return target_url when Net::HTTPRedirection then target_url = res["location"] else return res.value end end end 省略されている URL (t.co …
今回以下の様なクラスを作成して、 インスタンス変数(今回は @name )の値が同じ場合にハッシュで同一キーと判定してほしかった。 class HashKey def initialize(name) @name = name end end 事前にいくつか必要なメソッドを見ていきます。 Object#equal? …
試したバージョン ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2] Date クラスのメソッドには wday と cwday があって2つとも曜日を数値で返します。 実際に 2014 年 4 月 13 日 日曜日を試してみます。 [2] pry(main)> d = Date.new(2…
[1] pry(main)> require 'net/http' => true [2] pry(main)> require 'net/http' => false require されているライブラリは $" で確認できる。 参考:http://docs.ruby-lang.org/ja/2.0.0/method/Kernel/m/require.html
def self.convert_to_original_url(omission_url, limit = 10) raise ArgumentError, 'http redirect too deep' if limit == 0 response = Net::HTTP.get_response(URI.parse(omission_url)) case response when Net::HTTPSuccess then omission_url when Ne…
今日、proxy環境でbundlerを使っててハマったのでメモ。 bundle install したら、 Network error while fetching って出る。 あ、proxyだなー。と思って、設定方法を色々調べてたら、 .gemrcに http_proxy: http://example.proxy.com:8080/ って書けばいいよ…