Forum: Ruby-core [ruby-trunk - Feature #8038][Open] Keyword `object` to be used instead of `class <<`

Posted by alexeymuranov (Alexey Muranov) (Guest)
on 2013-03-07 06:59
(Received via mailing list)
Issue #8038 has been reported by alexeymuranov (Alexey Muranov).

----------------------------------------
Feature #8038: Keyword `object` to be used instead of `class <<`
https://bugs.ruby-lang.org/issues/8038

Author: alexeymuranov (Alexey Muranov)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: Next Major


=begin
I propose to introduce a new keyword (({object})) and to use it instead 
of the mysterious (({class <<})):

  object foo
    def bar
      # ...
    end
    def baz
      # ...
    end
  end

instead of

  foo = Object.new
  class << foo
    def bar
      # ...
    end
    def baz
      # ...
    end
  end
=end
Posted by David MacMahon (Guest)
on 2013-03-07 07:12
(Received via mailing list)
As an alternative, how about allowing Object#extend to take a block that 
would be executed with the context such that methods defined therein 
would become singleton methods of the object receiving #extend?

Your example would then become:

 foo = Object.new
 foo.extend do
   def bar
     # ...
   end
   def baz
     # ...
   end
 end

Sorry if this is impossible for some reason I don't know of,
Dave
Posted by matz (Yukihiro Matsumoto) (Guest)
on 2013-03-07 07:27
(Received via mailing list)
Issue #8038 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected

Introducing a new keyword would break a lot of existing programs.  We 
don't want to do unless there's strong requirement.
Making Object#extend to take a block is interesting idea.  We will 
discuss later if it's submitted.

Matz.

----------------------------------------
Feature #8038: Keyword `object` to be used instead of `class <<`
https://bugs.ruby-lang.org/issues/8038#change-37353

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee:
Category: core
Target version: Next Major


=begin
I propose to introduce a new keyword (({object})) and to use it instead 
of the mysterious (({class <<})):

  object foo
    def bar
      # ...
    end
    def baz
      # ...
    end
  end

instead of

  foo = Object.new
  class << foo
    def bar
      # ...
    end
    def baz
      # ...
    end
  end
=end
Posted by Thomas Sawyer (7rans)
on 2013-03-07 09:04
(Received via mailing list)
Issue #8038 has been updated by trans (Thomas Sawyer).


@alexey I sympathize. I tend to avoid `class << foo` too b/c it "reads" 
so poorly.

@david Facets extends #extend to do that actually, but it does not add 
the the methods directly. Instead it creates an anonymous module which 
it includes into the singleton class. In this way it behaves the same as 
extending with a module.

----------------------------------------
Feature #8038: Keyword `object` to be used instead of `class <<`
https://bugs.ruby-lang.org/issues/8038#change-37354

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee:
Category: core
Target version: Next Major


=begin
I propose to introduce a new keyword (({object})) and to use it instead 
of the mysterious (({class <<})):

  object foo
    def bar
      # ...
    end
    def baz
      # ...
    end
  end

instead of

  foo = Object.new
  class << foo
    def bar
      # ...
    end
    def baz
      # ...
    end
  end
=end
Posted by Matthew Kerwin (mattyk)
on 2013-03-08 03:53
(Received via mailing list)
Issue #8038 has been updated by phluid61 (Matthew Kerwin).


matz (Yukihiro Matsumoto) wrote:
> Introducing a new keyword would break a lot of existing programs.  We don't want 
to do unless there's strong requirement.
> Making Object#extend to take a block is interesting idea.  We will discuss later 
if it's submitted.
>
> Matz.

I'm interested in this discussion, including Facets' interpretation.  I 
just created #8046
----------------------------------------
Feature #8038: Keyword `object` to be used instead of `class <<`
https://bugs.ruby-lang.org/issues/8038#change-37375

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee:
Category: core
Target version: Next Major


=begin
I propose to introduce a new keyword (({object})) and to use it instead 
of the mysterious (({class <<})):

  object foo
    def bar
      # ...
    end
    def baz
      # ...
    end
  end

instead of

  foo = Object.new
  class << foo
    def bar
      # ...
    end
    def baz
      # ...
    end
  end
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.