Cloning only when necessary

Discussion in 'Ruby' started by Robert Klemme, Oct 29, 2009.

  1. Hi,

    if you want to make sure you get a copy of an instance that nobody
    else has access to you can #clone it. That's not necessary if the
    instance is immutable or frozen (or both). Does anybody think it is a
    good idea to implement this? E.g.

    class Object
    def frown
    frozen? ? self : clone
    end
    end

    class Numeric
    def frown
    self
    end
    end

    ...

    The you can do in constructor code for example

    def initialize(something)
    @x = something.frown
    end

    and be sure that you do not face aliasing issues with @x. Does
    anybody think we should have this in the language?

    Note: The name is remotely inspired by "FReeze" and "OWN". I'm not
    religious about it, not at all. It's just that I could not make up a
    better one. Suggestions welcome.

    Kind regards

    robert

    --
    remember.guy do |as, often| as.you_can - without end
    http://blog.rubybestpractices.com/
     
    Robert Klemme, Oct 29, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    Cloning Possible?

    Guest, Nov 10, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    409
    Steve C. Orr [MVP, MCSD]
    Nov 11, 2003
  2. =?Utf-8?B?QVZM?=

    cloning

    =?Utf-8?B?QVZM?=, Dec 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    504
    Eliyahu Goldin
    Dec 14, 2004
  3. Joel Leong

    Cloning ASPNET account

    Joel Leong, Jun 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    363
    Scott Allen
    Jun 4, 2005
  4. Neven Klofutar

    Deep cloning

    Neven Klofutar, Jul 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    445
    =?Utf-8?B?bG9uZG9uIGNhbGxpbmc=?=
    Jul 7, 2005
  5. =?Utf-8?B?UCBL?=

    Datasets - Cloning problems

    =?Utf-8?B?UCBL?=, Mar 31, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    384
    sirfunusa
    Mar 31, 2006
Loading...

Share This Page