ruby-units icon indicating copy to clipboard operation
ruby-units copied to clipboard

Feature Request/Question: Unit.is_valid?("unitname")

Open johnhutch opened this issue 8 years ago • 3 comments

Hey there! I'm wondering if there's currently a way to do something like the above, or what you recommend if one wanted to determine whether or not one is using a valid unit, or if you think it's better to rescue the exception. Thanks!

johnhutch avatar Jun 07 '17 03:06 johnhutch

right now you will have to rescue the exception thrown when parsing. It's a good suggestion that I will explore incorporating in the next version.

olbrich avatar Jun 07 '17 14:06 olbrich

Thanks much!

johnhutch avatar Jun 07 '17 16:06 johnhutch

@johnhutch I think you can use Unit.defined?("unitname") for this purpose. Edit: Unit.defined? does not recognize prefixes so it won't work for those cases e.g. Unit.defined?('cm') is false but Unit.new('cm') will work.

dipil-saud avatar Dec 19 '17 06:12 dipil-saud