-
-
Save iwadon/586533 to your computer and use it in GitHub Desktop.
dRuby経由で生成されたオブジェクトのinitializeメソッドがいつどこで呼び出されるかについて。
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
| require 'drb/drb' | |
| require_relative 'object' | |
| require_relative 'foo' | |
| DRb.start_service | |
| foo_s = DRbObject.new_with_uri('druby://localhost:8787') | |
| p foo_s | |
| p(foo = foo_s.foo(123)) |
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
| class Foo | |
| def initialize(x) | |
| @x = x | |
| @created_at = Time.now | |
| end | |
| end |
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
| class Object | |
| alias_method :initialize_orig, :initialize | |
| def initialize(*args) | |
| @created_at = Time.now | |
| p([:Object_initialize, self, @created_at]) | |
| initialize_orig(*args) | |
| end | |
| end | |
| class DRbObject | |
| alias_method :initialize_orig, :initialize | |
| def initialize(*args) | |
| @created_at = Time.now | |
| p([:DRbObject_initialize, self.class, @created_at]) | |
| initialize_orig(*args) | |
| end | |
| end |
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
| require 'drb/drb' | |
| require_relative 'object' | |
| require_relative 'foo' | |
| class FooServer | |
| def foo(x) | |
| obj = Foo.new(x) | |
| p([:FooServer_foo, Time.now, obj]) | |
| obj | |
| end | |
| end | |
| foo_s = FooServer.new | |
| DRb.start_service('druby://localhost:8787', foo_s) | |
| DRb.thread.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment