Skip to content

Instantly share code, notes, and snippets.

@osyo-manga
Created November 24, 2015 04:56
Show Gist options
  • Select an option

  • Save osyo-manga/acf535347ed16b0a5a61 to your computer and use it in GitHub Desktop.

Select an option

Save osyo-manga/acf535347ed16b0a5a61 to your computer and use it in GitHub Desktop.
call_one
def call_one &block
result = nil
proc { |*args| result ||= instance_exec(*args, &block) }
end
twice = call_one { |a| a + a }
p twice.call "homu"
p twice.call "mami"
class X
define_method(:initialize, &call_one do
p "init"
@name = "mado"
end)
end
p X.new.instance_eval { @name }
p X.new.instance_eval { @name }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment