Some critique
-
I made some Ruby tutorials for sketchup to use in our office. They are a but rough around the edges as they've not really stretched their legs yet. I'd be really interested in getting some feedback on them. If anyone fancies having a look at them then I'd be really grateful!
-
Lesson 1
@unknownuser said:
Variables are places to store information, a bit like a jar. Lets make a jar to put our name in.
Ruby does NOT have variables, despite what some texts say, nor what some of the query methods are named, like: .instance_variables().
Ruby is a 100% OOP language. Ruby has 2 "kinds" of things, objects and references that point at objects. If you teach your students to think about Ruby references, the way they think about BASIC variables, you will set them up for frustration down the road.
In Ruby = is not "equals", it is the reference assignment operator. (== is the equality comparison operator or method.)
see these topics:
@unknownuser said:
There are lots of different types of variables:
numbers: 1, 5000, 20, or like 4.5, -700.45
strings: 'hello world', "my style is the best"
Booleans: true, false
This should read, "There are many different classes of objects"
-
Dan, Help me out. As a old timer that cut his tooth on pre-OPPS, what is the equivalent of a C variable in OPPS?
-
Dan is trying to explain the correct terminology
model=Sketchup.active_model
sets a reference named 'model' to the Sketchup active_model object.
In layman speak you set the variable named 'model' equal to the Sketchup active_model.
A reference is what you might [sloppily] call a variable and using 'equal' because it uses a = sign is also potentially confusing as == tests for equality, whilst = assigns a reference.
Assigning a 'reference' also has different effects depending on the 'type' [class] of object referenced
With numbers...
x=1 returns 1
y=x returns 1
y=2 returns 2
but then
x still returns 1 as x and y are not 'linked'.
BUT
xyz=[1,2,3] returns 1,2,3
abc=xyz returns 1,2,3
abc[0]=0 returns 0,2,3
but now
xyz returns 0,2,3 too, because abc AND xyz refer to the same array, changing one reference changes the other, as they are both referring to the same thing...
To make a new array you need to use abc=xyz.dup or abc=xyz+[] etc, now they are references to two separate arrays that can be changed independently. -
Thanks chaps. In some odd way I knew that, well, I owned all the bits of information, I just hadn't assembled them yet. I've updated it so that lesson 1 reads better (i.e. no variables)
I'll go through and check the others now. -
TIG, Thanks.
-
Saying that Ruby doesn't have variables is plain wrong though. Even if the variables just hold references to objects, they're still variables, and the term "instance variable" is found throughout most object oriented programming languages (and I think the fact that Matz himself calls them variables is proof enough that Ruby has variables :))
Of course it might be wrong to compare BASIC variables and Ruby variables, but then it's also wrong to compare apples and oranges.
Advertisement