ib-ruby / ib-extensions

Helpers and Macros that ease the usage of the TWS-API of Interactive Brokers through IB-Ruby
https://ib-ruby/github.io/ib-doc
0 stars 1 forks source link

IB::Contract in ib-extensions has different superclass (Object) than ib-api #7

Open pelly opened 2 years ago

pelly commented 2 years ago

IB::Contract defined in https://github.com/ib-ruby/ib-extensions/blob/master/lib/ib/models/contract.rb has Object as it's superclass (since it doesn't extend any class explicitly)

But IB::Contract defined in https://github.com/ib-ruby/ib-api/blob/master/lib/models/ib/contract.rb has IB::Model as its superclass.

As a result, requiring both of these files will cause a mismatched superclass exception:

/home/user/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/ib-api-972.5/lib/models/ib/contract.rb:14:in `<module:IB>': superclass mismatch for class Contract (TypeError)
    from /home/user/.rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems/ib-api-972.5/lib/models/ib/contract.rb:6:in `<top (required)>'
    from <internal:/home/user/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
    from <internal:/home/user/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
topofocus commented 2 years ago

Hi, the contract class in ib-extensions reopens IB::Contract defined in ib-api.

As ib-extensions depends on ib-api, IB::Contract should always been initialized before the model-file in ib-extensions is parsed.

How do you initialize ib-extensions?

pelly commented 2 years ago

I'm trying to bring in technical-analysis which I think brings in ib-extensions.

I've run into issues like this before. I believe this bug surfaces depending on how the filesystem lays out files - different ordering for different OS installs (even different linux distros). So sometimes requiring technical-analysis will bring in ib-extensions' "ib/model/contract" before ib-api's "models/ib/contract".

An easier (while also still robust) way would be to ensure that ib-extensions' "ib/model/contract.rb" file requires ib-api's "models/ib/contract". I can submit a PR for that if you prefer.

On Wed, Nov 10, 2021 at 4:29 AM Hartmut Bischoff @.***> wrote:

Hi, the contract class in ib-extensions reopens IB::Contract defined in ib-api.

As ib-extensions depends on ib-api, IB::Contract should always been initilized before the model-file in ib-extension is parsed.

How do you initialize ib-extensions?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ib-ruby/ib-extensions/issues/7#issuecomment-964996033, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABJBGHPVQFPPMOYIRZ2LGLULJCP7ANCNFSM5HS6XIPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

topofocus commented 2 years ago

Thanks for bringing this to my attention. You are right, its considered as bad practice to reopen classes across ruby-gems.

A proper solution would to use mixins and include/prepend them later.

That would translate in a change of the design of ib-extensions.

Your opinion?

pelly commented 2 years ago

That sounds reasonable to me.

In general the thing that is extending a class has to know about that class and ensure that it is initialized correctly in a certain state. So I always like to ensure I've required the original "base" class that I'm reopening / extending.

On Fri, Nov 12, 2021 at 9:45 PM Hartmut Bischoff @.***> wrote:

Thanks for bringing this to my attention. You are right, its considered as bad practice to reopen classes across ruby-gems.

A proper solution would to use mixins and include/prepend them later.

That would translate in a change of the design of ib-extensions.

Your opinion?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ib-ruby/ib-extensions/issues/7#issuecomment-967773376, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABJBGFF32RUNMG2KINZDHLULXNLZANCNFSM5HS6XIPA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.