LoginSignup
2
2

More than 5 years have passed since last update.

BubbleWrap::HTTP.getのブロック内にyield実行させようとしたらエラー

Posted at

これと同じ問題だった。
http://d.hatena.ne.jp/hokaccha/20130725/1374760838

bubble-wrap-httpのソースを読むと、callで呼ぶようになってるのでたぶんこれが原因。
https://github.com/rubymotion/BubbleWrap-HTTP/blob/master/motion/http/query.rb#L397

じゃあどうするか。
取り敢えずは以下のようにデリゲート用メソッドを加える形で解決しました。

class SpotSearch
  attr_accessor :delegate

  def initialize(attributes = {})
  end

  def find(keyword)
    # ... urlとかpayloadとか色々指定済みということで ...
    BW::HTTP.get(url, payload: payload) do |response|
      @delegate.call(response) if @delegate
    end
  end
end

search = SpotSearch.new
search.delegate = Proc.new {|response|
  puts response # -> ちゃんと動く
}
search.find('銀座 カフェ')

最終的にはもっとスマートにメソッドを登録、呼び出しができればいいのだと思う。
色々ハマったけど、おかげでブロックとかProcとか少し理解できました。

2
2
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
2
2