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

Extending existing measurements #11

Open
MyklClason opened this issue Dec 2, 2016 · 2 comments
Open

Extending existing measurements #11

MyklClason opened this issue Dec 2, 2016 · 2 comments

Comments

@MyklClason
Copy link

Decided to make an issue out PR #8 (comment). Summa, was I wanted to discuss how to go about extending the code. Anyone is free to write the code themselves, I just wanted to think a bit on how to go about it in case I have a need to implement it.

After reviewing the code for a bit, it seems like the key is to slightly re-configure how the Builder class works. Looks like the easy way is to change how builder initialize works, so that it can use an existing unit rather than creating a new one. Measurement.extend would then use this alternative approach to extend the existing unit rather than overwrite it.

Specifically this line of code would need to be changed in the Builder class to some sort of lookup to check if the unit already exists. Sadly, my Ruby knowledge is a bit lacking as to how exactly to go about it.

@unit = Unit.new(unit_name)

@unit = Unit.new(unit_name)

Thoughts?

Does that seem reasonable?

@MyklClason MyklClason changed the title Easier extension of existing measurements Extending existing measurements Dec 2, 2016
@mhuggins
Copy link
Owner

mhuggins commented Dec 2, 2016

The line you called out in Builder could probably just be changed from this:

@unit = Unit.new(unit_name)

to this:

@unit = Unit[unit_name] || Unit.new(unit_name)

@mhuggins
Copy link
Owner

mhuggins commented Dec 2, 2016

One benefit of that change too is that you would no longer need to define a new extend method, but could just reuse the define method to append new info to a unit.

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