Go Back   CodingForums.com > :: Server side development > Ruby & Ruby On Rails

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-22-2010, 02:42 AM   PM User | #1
chrisglasier
New Coder

 
Join Date: Dec 2009
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
chrisglasier is an unknown quantity at this point
Add method to existing class

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
__________________
glasier.hk
chrisglasier is offline   Reply With Quote
Old 01-10-2011, 11:57 PM   PM User | #2
JamieD
New Coder

 
Join Date: May 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
JamieD is an unknown quantity at this point
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:

Code:
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:

Code:
class Bone
  attr_accessor :name
end
Which would create getter and setter methods for the @name attribute
__________________
Flexible UK web hosting solutions for designers and developers
PHP5, Ruby on Rails, MySQL, spam and virus filtering
UK Hosting from Media72, Media72 on twitter
JamieD is offline   Reply With Quote
Old 01-11-2011, 01:20 AM   PM User | #3
chrisglasier
New Coder

 
Join Date: Dec 2009
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
chrisglasier is an unknown quantity at this point
Thanks for the the reply. I'm onto something else but will return soon to try out your suggestions. Thanks
__________________
glasier.hk
chrisglasier is offline   Reply With Quote
Old 01-18-2011, 06:01 AM   PM User | #4
chrisglasier
New Coder

 
Join Date: Dec 2009
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
chrisglasier is an unknown quantity at this point
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
Attached Files
File Type: zip skel_animation.zip (2.1 KB, 108 views)
__________________
glasier.hk
chrisglasier is offline   Reply With Quote
Old 01-19-2011, 07:52 AM   PM User | #5
chrisglasier
New Coder

 
Join Date: Dec 2009
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
chrisglasier is an unknown quantity at this point
... and a pic.
Attached Thumbnails
Click image for larger version

Name:	Skel in progress.gif
Views:	130
Size:	22.0 KB
ID:	9291  
__________________
glasier.hk
chrisglasier is offline   Reply With Quote
Old 01-20-2011, 07:24 AM   PM User | #6
chrisglasier
New Coder

 
Join Date: Dec 2009
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
chrisglasier is an unknown quantity at this point
Code:
class Bone
  attr_accessor :name
end
Just figured out how to fit it in - works great! Thanks
__________________
glasier.hk
chrisglasier is offline   Reply With Quote
Old 08-24-2011, 09:12 AM   PM User | #7
chrisglasier
New Coder

 
Join Date: Dec 2009
Posts: 70
Thanks: 4
Thanked 0 Times in 0 Posts
chrisglasier is an unknown quantity at this point
... 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!
__________________
glasier.hk
chrisglasier is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:21 PM.


Advertisement
Log in to turn off these ads.