Ruby class and module namespace identifiers should be CamelCase (aka SnakeCase.)
Local variables are all lowercase in Ruby.
So the submodule needs to at least begin with a lowercase character, like Flt
.
In fact the project README file states …
All types and functions are within a namespace called Flt
.
module MyCompany
module MyProject
module Flt
...
If the module (or class) is a library to access a filetype or some thing universally known by a short acronym (such as a trademark) then it can be all uppercase. (Examples would be the CSV
and JSON
libraries for file types; or companies like IBM
, ASUS
, etc.; Operating systems ie: IOS
, etc.; Interfaces: USB
, MIDI
, etc. I think you should get the idea.)
Again it’s Float
not float
.
And …
-
you cannot wrap Ruby Core base classes !
They must remain defined in the toplevel Objectspace.
-
SketchUp’s Ruby process is a shared process.
It is not permitted for SketchUp extensions to directly modify Ruby Core classes or modules.
So if you are thinking of using this library for a SketchUp extension that you will publish, then don’t.
You could use it only for yourself if you really had to, but as it changes several Ruby core classes if this interfered with any other SketchUp extension, this would violate any warranty implied by the affected extensions. Ie, don’t expect to get a refund if your use of this library breaks paid extensions.
There might be the possibility of rewriting this library as a Ruby refinement that only your extension uses. Or … rewriting the core class changes as refinements that only this library uses.
There is also the quirk that SketchUp’s Length
class was previously a subclass of Float
but is no longer for some quirky implementational reason.
My mention here is prompted by possible issues in converting objects between Length
and Float
.
Also, at the bottom of the "float.rb"
file …
# Is Float('...') correctly rounded, even for subnormal numbers?
def Flt.float_correctly_rounded?
# That doesn't seem to be the case for mswin32
@float_correctly_rounded ||= RUBY_PLATFORM.match(/mswin32/).nil?
end
The test against the global RUBY_PLATFORM
constant is unreliable as the platform substring has varied over the recent SketchUp versions.
Use the Sketchup::platform
method for versions greater than 14.
EDIT: I’ll revise my thinking per my comments in a following post. (A platform only test may not be adequate.)
# Is Float('...') correctly rounded, even for subnormal numbers?
def Flt.float_correctly_rounded?
# That doesn't seem to be the case for mswin32
if Sketchup.respond_to?(:platform)
@float_correctly_rounded ||= Sketchup.platform != :platform_win
else
@float_correctly_rounded ||= RUBY_PLATFORM.match(/mswin32/).nil?
end
end
Also at the bottom of the "float.rb"
file …
# Return a (limited) context object for Float.
# This eases the implementation of functions compatible with either Num or Float values.
def Float.context
Flt::FloatContext.instance
end
… would need to qualify the method call with your wrapping namespaces …
def Float.context
MyCompany::MyProject::Flt::FloatContext.instance
end
This necessary call qualification would also need to happen other places in the gem’s code.
I haven’t looked through all the files to know what other things need “adjustment”.