Skip to content

Instantly share code, notes, and snippets.

@ainame
Last active December 17, 2015 18:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ainame/5651453 to your computer and use it in GitHub Desktop.
Save ainame/5651453 to your computer and use it in GitHub Desktop.
rubymotionバグ? block_given?がブロックの中で評価すると値が変わる
def callback_caller(&block)
p block_given?
callback_caller2 do
p block_given?
block.call if block_given?
end
end
def callback_caller2(&block)
block.call
end
callback_caller do
p 'origin'
end
# $ ruby -v
# ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]
# $ /Library/RubyMotion/bin/ruby -v
# RubyMotion (ruby 1.9.2) [universal-darwin12.0, x86_64]
# $ ruby a.rb
# true
# true
# "origin"
# $ /Library/RubyMotion/bin/ruby a.rb
# true
# false
# -*- coding: utf-8 -*-
# a part of api client
def refresh_access_token(refresh_token, &block)
body = {
grant_type: "refresh_token",
client_id: CONSUMER_KEY,
client_secret: CONSUMER_SECRET,
refresh_token: refresh_token,
}
p is_block_given = block_given? # => true
BW::HTTP.post(TOKEN_URL, payload: body) do |response|
if json = BW::JSON.parse(response.body.to_s)
@refresh_token = json['refresh_token']
@access_token = json['access_token']
end
p block_given? # => false
block.call if is_block_given # will execute
block.call if block_given? # will don't execute
end
end
# another file
def viewDidAppear(animated)
App.shared.delegate.api_client.
refresh_access_token(App::Persistence['refresh_token']) do
fetch_tweets
updateViewConstraints
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment