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

  • Home
  • SEARCH
  • 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 5964357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:25:02+00:00 2026-05-22T19:25:02+00:00

Problem! I was wondering if it is possible for an array to be transfered

  • 0

Problem!

I was wondering if it is possible for an array to be transfered into a virtual object via method. Let’s say that I have a class “Person” with two properties “@name” and “@lastname” and then I have an array containing this information, so What I need is to pass each array item into a new object from Person’s class.

Example #

class Person
  attr_accessor :name, :lastname
  def initialize(name = "", lastname = "")
    @name = name
    @lastname = lastname
  end
end

array_of_names = [["lucia", "germes"], ["eder", "quiñones"], ["pedro", "infante"]]
array_of_names.each_with_index do |item, index|
  virtual_object = item.to_vo(Person.new)
  virtual_object.inspect
  # => "#<Person:0x0000FF @name="eder" @lastname="quiñones">
end

Question?

Is this even possible by extending Array’s class?

class Array
  def to_vo(object)
    # ...
    # ...
    # ...
  end
end

Any help would be highly appreciated

~ Eder Quiñones

  • 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-05-22T19:25:04+00:00Added an answer on May 22, 2026 at 7:25 pm

    Yes

    class Array
      def to_vo klass
        klass.new *self
      end
      # ..OR..
      def to_person
        Person.new *self
      end
    end
    
    p a.map { |e| e.to_vo Person }
    p a.map(&:to_person)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering, because of a problem I am running into, is it possible to
I am wondering how you would approach this problem I have two Taxrates that
I have a problem related to the subset sum problem and am wondering if
I'm wondering if is possible pass types by argument in Java. Let me explain
I'm currently working on a test plan and ran into a possible problem and
I am wondering if it is possible to avoid the lost update problem, where
I am wondering it is possible to have multiple GridFS in Mongo? The reason
Here's my problem: I have a table with 4 columns (type = array, one-dimension)
Im' wondering if this is possible: I've successfully used __set() magic method to set
I was wondering if it's possible in Android to declare different activities (say .ActivityA

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.