...

View Full Version : Add method to existing class



chrisglasier
12-22-2010, 02:42 AM
I use Sketchup's Ruby API to manipulate model components. I am using one class called Bone which does not have a method for giving a name to each bone (part of skeletal animation). I am more familiar with javascript than Ruby so would be grateful for some newby oriented advice about how to make and implement a naming method. Thanks

JamieD
01-10-2011, 11:57 PM
Without an example of the code I don't know what the Bone object implements, this is how you would define and instance method on the bone object:


class Bone
def give_name(name)
# manipulate the name here
end
end

If you post up the Bone class code it would help us to be able to shoe you how to actually change/assign the name. You may simply be able to do something like this:


class Bone
attr_accessor :name
end

Which would create getter and setter methods for the @name attribute

chrisglasier
01-11-2011, 01:20 AM
Thanks for the the reply. I'm onto something else but will return soon to try out your suggestions. Thanks

chrisglasier
01-18-2011, 06:01 AM
Here's the file. It is not made by me, but I want to use it as a required file to set up a skeleton. I need to give the bones names in my own code so that I can find and rotate them.

I am sure what you noted is fine but I am still not sure how to implement it.

Thanks

chrisglasier
01-19-2011, 07:52 AM
... and a pic.

chrisglasier
01-20-2011, 07:24 AM
class Bone
attr_accessor :name
end

Just figured out how to fit it in - works great! Thanks

chrisglasier
08-24-2011, 09:12 AM
... if you want to add methods to a class someone else has created. In my case, the original author had no need to name instances, but I did because I wanted to identify and animate each

... that was a long time ago!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum