Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8536105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:35:07+00:00 2026-06-11T10:35:07+00:00

I am dealing with fractals. You start with a rectangle, and that shape is

  • 0

I am dealing with fractals. You start with a rectangle, and that shape is decreased by a given decay rate. I have it set up to do the first 10 iterations of the given scenario, and each scenario looks like this:

y_1 = dec_y(y_1)
y_2 = dec_y(y_2)
a_y = [y_1, y_2]
rect_1 = TkcRectangle.new(canvas, [0,0], a_y)

where dec_y is defined as the following:

def dec_y(y)
    to_ret = y / $rate
    return to_ret
end

I want to turn the first snippet into a function/method (not exactly sure what the Ruby term is…), so that each iteration will just be a single line referencing a method, which makes the problem more extensible. But, I need each TkcRectangle to have a different name. The way I want to set it up, each TkcRectangle will have the same name. But, if I can set the name of the object to a string passed as an argument, then I should not have a problem.

How do I define the name of an object with a given string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:35:09+00:00Added an answer on June 11, 2026 at 10:35 am

    Edit : Code has not been tested, but will give you the idea.

    Instead of naming each element, you can use an array and use the index instead

    rectangles_array = Array.new
    for each loop
      rectangles_array << create_rectangle_object(y_1, y_2, canvas)
    end for each loop
    
    def dec_y(y)
      to_ret = y / $rate
      return to_ret
    end
    
    def create_rectangle_object(y_1, y_2, canvas)
      return TkcRectangle.new(canvas, [0,0], [dec_y(y_1), dec_y(y_2)])
    end
    

    If you really want to name it read about structs.. Something like

    MyRectangleStruct = Struct.new(:obj_name, :x1, :y1, :x2, :y2)
    puts MyRectangleStruct.new(:obj_name => 'First_rec', .....)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Other questions dealing with use of match_parent pre 2.2 have answers stating one should
I am dealing with very primitive HTML construction that goes like this: <a NAME=header1></a><b><font
When dealing with a flash application that will run in a browser, it's obvious
When dealing with websites with large amount of javascript, i see that these are
I'm dealing with a midlet in j2me, and I have this thread class (say
Recently I have been dealing with windows LogonUser API. The LogonUser api returns different
I am dealing with Cell and I have a problem because they are not
Dealing with go's funcs I discovered that one can't force the compiler to control
I'm dealing with a weird bug that I don't manage to fix. It's a
I am dealing with hundreds of thousands of files, I have to process those

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.