Skip to content

Instantly share code, notes, and snippets.

@serihiro
Last active March 9, 2018 06:52
Show Gist options
  • Select an option

  • Save serihiro/59c8c819742b92cf52939f50d64cbfec to your computer and use it in GitHub Desktop.

Select an option

Save serihiro/59c8c819742b92cf52939f50d64cbfec to your computer and use it in GitHub Desktop.
google drive rubyにPR出したいポイント

on_gce?の結果をメモ化してるところでfalseだったらメモ化しないでほしい

on_gce?は実際にためしたところ、30回試すと1回ぐらいの確立でfalseを返してくることがある

irb(main):055:0> 30.times {pp Google::Auth::GCECredentials._unmemoized_on_gce? }
true
true
true
true
true
true
true
true
true
true
true
true
true
true
false
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true

なので、falseを返してきてた時にraiseするのはまぁいいとして、 https://github.com/google/google-auth-library-ruby/blob/master/lib/googleauth/application_default.rb#L61 でraiseする前にcacheをクリアすべきである

memoist挙動実験用スクリプト

require 'bundler'

Bundler.require
require 'memoist'

class MoodyMan
  extend Memoist

  def random
    puts 'uei'
    Random.rand(10) > 1
  end

  memoize :random
end

man = MoodyMan.new

puts man.random
puts man.random
puts man.random
puts man.random
puts man.random
# puts man._unmemoized_random
# puts man._unmemoized_random
# puts man._unmemoized_random
# puts man._unmemoized_random
# puts man._unmemoized_random
man.unmemoize_all
puts man.random
puts man.random
puts man.random
puts man.random
puts man.random
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment