This is an OPTIONAL extension for Ruby that helps deal with the differing formats for RGB, RGB0, RGBA and ARGB color integers. [For more info see this thread..]
It is a Ruby extension for Sketchup, not an extension to Sketchup per se.
I know that some of you just hate to modify base classes, BUT... that's what the power of Ruby is all about. (I DO intend to submit it to RubyForge for inclusion into standard ruby, but it would not make it in until after 2.0.x sometime.) In the meantime you can use it as an add-in.
The base class in question, is the Integer class, and it's subclasses Fixnum and Bignum.
Clarification: As discussed in the thread below... these methods really belong within the class to which they provide benefit and functionality. This class or classes, would be any Color object class that is defined in ruby, for whatever purpose. The example code can be rewritten slightly, so as to make it a generic mix-in module, for including in any Color class definition. In this way any Color class could inherit the conversion methods in the mixin module. Such a module would have as it's first line "module ColorIntegerConversion" instead of "class ::Integer", and this will be the way that it would be submitted for Standard Ruby, NOT as an extension to the ruby base Integer class.
The script is not scrambled. I place it in the public domain. No Warranty, etc.
[Code] Ruby Extension for Sketchup color integers
7 posts
• Page 1 of 1
[Code] Ruby Extension for Sketchup color integersLast edited by Dan Rathbun on Fri Jan 06, 2012 7:40 am, edited 3 times in total.
Re: [Ruby Extension] for Sketchup color integersI'd love to extend classes - would make allot more practical. But it's the potential for conflicts seeing how all scripts share the same space.
Additions of methods are one thing - use at own risk. But modifications is a big no-no. Very clean code though. Well documented. Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Ruby Extension] for Sketchup color integersI agree with Tom.
We should NEVER extend built-in classes, especially the native Ruby ones. You can perfectly publish your functionality as a custom class taking an integer parameter. Alternatively, you can create a custom subclass of Integer, which contains the additional methods. I am not familiar with color coding conversion, but I guess this applies in specific contexts, where you can perfectly accept to use specific variables created on purpose for this usage, through one or the other methods above. Fredo
Re: [Ruby Extension] for Sketchup color integers
Thank you for the compliment sir! ![]() After 32 years in Engineering Documentation, I probably tend to overdocument; slap revision numbers on everything. ![]() This code is actually a triple exercise:
Re: [Ruby Extension] for Sketchup color integershmm... I was messing about with RDoc earlier. Can't remember from the top of my head right now. But I'll check out the examples I have bookmarked somewhere.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
Re: [Ruby Extension] for Sketchup color integersFirstly, I stated in the 2 posts, (the root of this thread,) that it was OPTIONAL; and (in the API doc thread,) that it was TEMPORARY.
(I went back and re-emphasized those words in both posts, by bold caps.) TRUE !! And this IS in the works. I've been working on the SKX extension for the Sketchup::Color class. These functions will be added in, because that's WHERE they REALLY belong! (I needed to write them up separately, for testing before adding them in. ...AND there's no way of telling when the first SKX release will happen.) Too cumbersome... the Color class method implementation is the norm.
Re: [Ruby Extension] for Sketchup color integersAdded to the original post (root of thread,):
Clarification: As discussed in the thread below... these methods really belong within the class to which they provide benefit and functionality. This class or classes, would be any Color object class that is defined in ruby, for whatever purpose. The example code can be rewritten slightly, so as to make it a generic mix-in module, for including in any Color class definition. In this way any Color class could inherit the conversion methods in the mixin module. Such a module would have as it's first line "module ColorIntegerConversion" instead of "class ::Integer", and this will be the way that it would be submitted for Standard Ruby, NOT as an extension to the ruby base Integer class.
7 posts
• Page 1 of 1
|
Who is online
Users browsing this forum: No registered users and 13 guests