[code] beta Group/Image parent, glued_to? etc.

Moderator: Jim

Re: [code] beta Group/Image parent, glued_to? etc.

Postby thomthom » Sat Jul 10, 2010 12:08 pm

Dan Rathbun wrote:def test; (0..9).each { |i| return 'hello world' if i == 7; puts i.to_s }; end
>> nil

I get no output at all.

That line just defines the method test. When you call test it returns 'hello world'.


Range or Array - same result:
> def test; [0,1,2,3,4,5].each { |i| return 'hello world' if i == 3 }; end
nil
> test
hello world
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] beta Group/Image parent, glued_to? etc.

Postby thomthom » Sat Jul 10, 2010 12:09 pm

Dan Rathbun wrote:..and you just made me override the Object.test method (from Kernel.) [shoulda known better.][/color]


oopsie!
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] beta Group/Image parent, glued_to? etc.

Postby Dan Rathbun » Sat Jul 10, 2010 12:11 pm

Strange... this works

def test; (0..9).to_a.each { |i| return 'hello world' if i == 7; puts i.to_s }; end
nil
test
0
1
2
3
4
5
6
hello world
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    Re: [code] beta Group/Image parent, glued_to? etc.

    Postby Dan Rathbun » Wed Jul 14, 2010 2:05 pm

    OK updated again with the .find {|i| boolean } block method.

    Much easier and more elegant. Those methods on pg 1 should work now.

    (Keep forgetting about Enumerable Mixin, because it's not listed in the API, or the old Pick-Axe book. I like how the new online Core Doc has the Mixins listed at the top of the page.)
    0
      I'm not here much anymore. But a PM will fire email notifications.
      User avatar
      Dan Rathbun 
      PluginStore Author
      PluginStore Author
       

      Re: [code] beta Group/Image parent, glued_to? etc.

      Postby Dan Rathbun » Thu Jul 15, 2010 4:14 am

      Updated again... all methods now at 0.6.0

      Fixed several typo booboos. (to myself I says, "Dang! I thought I changed that back in Rev 0.3.0, and my Rev Block says I did. Must be getting old.")

      And (prompted by another topic, where I was reminded of the dangers of iterating the C++ collections,) I revised the search methods to use Array copies. Even though they are not changing anything (in the other post, the poster was doing a similar non-changing search "in the context of a larger block of code," and somehow something ELSE (perhaps an Observer, perhaps Sketchup itself,) changed the Entities collection in the middle of the search, causing iterate errors.
      Whilst, I did that.. I also switched to using .length to get the size of the list, because it seems to be common between SU's C++ collections, and Ruby Arrays. Whereas the aliases, .count (SUAPI) and .size (Ruby) are not. (So if someone switched back to using the collection, it would not break the code, and visa versa. Note to self: I'll need to remember to always use .length from now on, in this situation.)

      Also fixed a stupid error in the conditional expressions, of both the .glued_to? methods. Basically I half reordered them from IF to UNLESS, but forgot to swap the true and false blocks, which has now been done. (Reason for this. For clarity, I like to have the raise Exception statements, in the same order as the boolean tests. If there's only one exception raised, the I usually use an IF expression, and the Exception is raised is in the ELSE block. But, if there are 2 exceptions raised, because of a nested conditional expression [as in this case,] it seems confusing to have the 1st raise exception, shown after the second. So I like to use an UNLESS for the outer expression, with the 1st exception in the upper 'false' block, and the nested conditional (normally an IF expression,) that raises the 2nd exception, down in the unless' ELSE block. That way the raised exceptions appear in the same order as the boolean tests.)
      Make sense ??
      0
        I'm not here much anymore. But a PM will fire email notifications.
        User avatar
        Dan Rathbun 
        PluginStore Author
        PluginStore Author
         

        SketchUcation One-Liner Adverts

        by Ad Machine » 5 minutes ago



        Ad Machine 
        Robot
         

        Previous


         

        Return to Skx Extension Library

        Who is online

        Users browsing this forum: No registered users and 1 guest

        Visit our sponsors: