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 8783135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:45:09+00:00 2026-06-13T20:45:09+00:00

I am creating a wrapper class for Ruby’s NArray (numeric array). I would like

  • 0

I am creating a wrapper class for Ruby’s NArray (numeric array). I would like my class to respond to all of the standard mathematical operators (+, +=, -, -=, *, *=, etc) in the same way that an instance of NArray does. I know how to make wrappers for Arrays and other Enumerable objects, include Enumerable in the wrapper, and define an each method that just redirects to the wrapped Enumerable object. I would like something similar with the NArray. Is there a single module to include/method I can define that will define the whole bevy of mathematical operators to target the wrapped NArray? Or do I have to define them all manually?

  • 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-13T20:45:11+00:00Added an answer on June 13, 2026 at 8:45 pm

    You could use Forwardable:

    require 'forwardable'
    class MyWrapper
    
      extend Forwardable
      def_delegators :@narray, :+, :*, # etc...
    
      def initialize(narray)
        @narray = narray
      end
    end
    

    I’m not sure this will work with the += et al methods (I don’t know exactly how they are implemented, but I believe they are a feature of the parser and not actually methods you can reference).

    Calling += on an instance of MyWrapper would set the reference to the result of that operation, so you would need to figure out a way for that to return the same instance. That raises the question – is that what you want to do (return a wrapped NArray as the result of mathematical operations), or do you expect your NArray to handle the returns?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a wrapper class in .NET (VB.NET as it happens but is
I'm creating 'generic' wrapper above SQL procedures, and I can resolve all required parameters'
Alright so I just want to confirm something. I am creating a wrapper class
When creating a BSTR (using _bstr_t as wrapper class) I have to use some
First for all I would like to start by saying I am relatively new
I'm working on creating wrapper classes for some HTML elements and I'd like to
From my understanding the Adapter pattern is basically creating a wrapper on another class
I'm creating a wrapper class in the Zend framework to encapsulate some data output
I am creating a .net managed wrapper. All the code is in C++ and
(Rephrased the question) I'm creating a wrapper class for boost normal distribution, and want

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.