Created
November 24, 2015 04:56
-
-
Save osyo-manga/acf535347ed16b0a5a61 to your computer and use it in GitHub Desktop.
call_one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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