mhuggins / ruby-measurement

Simple Ruby gem for calculating and converting measurements.
MIT License
46 stars 21 forks source link

.to_unit with subset of measurements #19

Closed emersonthis closed 5 years ago

emersonthis commented 5 years ago
gem 'ruby-measurement'

^ with this in my Gemfile, "dozen".to_unit works as expected.

When I follow the instructions on the README to load a subset of measurements, .to_unit is undefined. Ex:

require 'ruby-measurement/measurement'
require 'ruby-measurement/definitions/metric/volume'
require 'ruby-measurement/definitions/metric/weight'
require 'ruby-measurement/definitions/us_customary/volume'
require 'ruby-measurement/definitions/us_customary/weight'

Is this expected?

mhuggins commented 5 years ago

Yes, this is expected. It is a way of bypassing changes to global objects. You can ensure that still works by including that following:

require 'ruby-measurement/core_ext'

Sorry it's not clear in the documentation, I'd happily accept a PR to address it!

emersonthis commented 5 years ago

I think I see what happened, I spaced out and copy/pasted the example from the README without noticing the requires instead of gem. Closing this and opening a new issue to ask about the right way to do this.

emersonthis commented 5 years ago

@mhuggins I just saw your last reply... I'm working on a Rails project. Is there a way to only require the sub-libraries using Bundler?

mhuggins commented 5 years ago

Bundler only allows you a single require in lieu of the gem name. So with that in mind, no. πŸ˜„

emersonthis commented 5 years ago

Got it. I don’t know much about Bundler (the mark of a good package manager) but it looks like the require: option might do this. But I dunno...

On Jul 18, 2019, at 9:27 PM, Matt Huggins notifications@github.com wrote:

Bundler only allows you a single require in lieu of the gem name. So with that in mind, no. πŸ˜„

β€” You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

mhuggins commented 5 years ago

Yeah, the require option will only allow one require though, not multiple.