Variables?
-
can anyone explain to me or point me at a page that will explain what the words between the () are for, such as, (origin, mywidth, height, container, close) any help is appreciated thanks
def MyClass.rectangle(origin, mywidth, height, container, close) v1 = Geom;;Vector3d.new(mywidth,0,0) v2 = Geom;;Vector3d.new(0,height,0) p1 = origin; p2 = origin + v1 p3 = p2 + v2 p4 = origin + v2 edges = [] edges[0]=container.add_line p1, p2 edges[1]=container.add_line p2, p3 edges[2]=container.add_line p3, p4 edges[3]=container.add_line p4, p1 if( close ) f = container.add_face edges else edges end end
-
That is the arguments which the method requires.
Here's a nice little article on method arguments: http://www.skorks.com/2009/08/method-arguments-in-ruby/
-
Those are variables that get passed into that method. So when a script calls the "MyClass.rectangle" method, you have to supply it with the arguments for "origin", "mywidth", "height", "container", and "close".
Are you wanting to use that code in something? If so, you will need to spend a day or so learning ruby.
The tutorial by Chris Pine on ruby is my absolute favorite for learning enough ruby to get started very quickly. Check it out here:
Chris
-
arguments can have default values?
Now that I understand ruby better, I need to re-read all the tutorials and manuals. I am sure there are lots of cool little things like that, that I am missing out on.
Chris
-
@chris fullmer said:
arguments can have default values?
Oh yes.
Very nice construct. and the argument list , using * -
method(*args)
is also very nice to make methods accept multiple types of input. Like the ones you see in the Ruby API.@chris fullmer said:
Now that I understand ruby better, I need to re-read all the tutorials and manuals. I am sure there are lots of cool little things like that, that I am missing out on.
When I go back to update an older plugin I wrote - I usually end up cleaning up a bit. I can see what I've learned and how my ruby coding style have changed over this last year. (Think it just passed one year since I picked up SU Ruby coding. - About the same time as you, Chris?)
When I do these little cleanup - I usually end up stripping away many lines of code. -
Thanks guys, I am just starting and trying to learn what I can by reading and analyzing existing scripts. This bit of code is from a script I am looking over and trying to comprehend. i will definitely take a look at those suggestions, Thanks!
-
@thomthom said:
(Think it just passed one year since I picked up SU Ruby coding. - About the same time as you, Chris?)
Yeah, can you believe its just been about a year now that we've been doing this? I started learning Dynamic components jst before SU 7.0 was released publicly as I figured there would be lots of questions about them. Then I quickly realized I could do lots more if I just learned Ruby. It was right around then that I saw that you had jumped in and started learning Ruby. So of course, not to be outdone I had to do the same. And WOW I'm glad I did. I have really enjoyed learning ruby. Its god for my brain to think in code. Except for matrix transformations - those still get the best of me!
Chris
-
Transformations are still an enigma to me as well.
But I just got a couple of books on vectors and transformations. ...but my right eye is still blurry after the operation so I can't concentrate on reading.
Scariest of all is Observers. I wish you'd start using them more - so you could share my pain. (And join in on the rants
)
Advertisement