@spireup said:
Now Im just trying to get the syntax right for those inner args arrays. eg(not working)
class WidgetSet < Array
> end # class
>
> class Widget < Hash
>
> attr_accessor ;arg1, ;xPos, ;yPos, ;zPos, ;height, ;width, ;type
>
> def initialize(arg1, xPos, yPos, zPos, height, width, type)
>
> Hash.new["arg1", arg1, "xPos",xPos,"yPos",yPos,"height", height, "width", width,"type", type]
> @arg1 = arg1 ##etc for each arg
> MyWidgets < self
> end
It does you no good to construct an object without a reference to it (the line with Hash.new).
If you want to use a Hash, then use one for your Widgets. They need not be a custom subclass, unless you need custom methods. Hashes dont need attributes (instance refs,) because they use key / value pairs, instead.
my_widget_1 = {
'xPos' => 3.4,
'yPos' => 1.0,
'zPos' => 2.3,
'height' => 6.784,
'width' => 4.0,
'type' => "some_type"
}
There is another thread on how to save and retrieve hashes into/from an Attribute dictionary.
see: http://forums.sketchucation.com/viewtopic.php?f=180&t=30066
Arguments: *list_name compacts an argument list into a local array referenced by list_name
Within the method, you can access array elements using the [] method.
def some_method(*args)
@xPos =( args.size>0 ? args[0] ; 0.0 )
@yPos =( args.size>1 ? args[1] ; 0.0 )
# etc.
end
If you use 5 arguments, but a call gives more than 5, the addtional arguments will be still be stored in the local array, and no ArgumentError, will be raised.
I suggest you visit the Code Snippet index:
http://forums.sketchucation.com/viewtopic.php?f=180&t=28846&p=323876#p322175