Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ruby safe import in production code #16

Open
gnecula opened this issue Oct 21, 2015 · 1 comment
Open

ruby safe import in production code #16

gnecula opened this issue Oct 21, 2015 · 1 comment

Comments

@gnecula
Copy link
Owner

gnecula commented Oct 21, 2015

I do not understand this safe import. Does this allow "if bond.testing" ? Why do we need the DUMMY_BOND name, can't we just assign to bond directly?

begin
require 'bond'
rescue LoadError
module BondTargetable
DUMMY_BOND = Class.new { def method_missing(meth, *args); end }.new
def self.included(base); base.extend(BondTargetable); end
def bond; DUMMY_BOND; end
end
end

@xkrogen
Copy link
Collaborator

xkrogen commented Oct 21, 2015

It doesn't allow for 'if bond.testing' at the moment; good point. I created
DUMMY_BOND so that it isn't creating and instantiating a new class on each
call to Bond, since this is supposed to be for production code, but it's
definitely not ideal. I was hoping to discuss some of the implementation
details with you when we met these week because there are some oddities
that I was hoping to get your opinion on.

Erik

On Wednesday, October 21, 2015, George Necula [email protected]
wrote:

I do not understand this safe import. Does this allow "if bond.testing" ?
Why do we need the DUMMY_BOND name, can't we just assign to bond directly?

begin
require 'bond'
rescue LoadError
module BondTargetable
DUMMY_BOND = Class.new { def method_missing(meth, *args); end }.new
def self.included(base); base.extend(BondTargetable); end
def bond; DUMMY_BOND; end
end
end


Reply to this email directly or view it on GitHub
#16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants