Hallo
How can I add methods to Enuerable??
class Enumerable end # => TypeError: Enumerable is not a class ##
Yes, its a module...
I want to have a method which can be used by Array, Hash and Enum likewise.
Maybe the question then is: How to change a Module?
Thank you
Opti
Enumerable is a Module not a class.
···
On Aug 17, 2022, at 7:01 PM, Die Optimisten <inform@die-optimisten.net> wrote:
Hallo
How can I add methods to Enuerable??
class Enumerable end # => TypeError: Enumerable is not a class ##
Yes, its a module...
I want to have a method which can be used by Array, Hash and Enum likewise.
Maybe the question then is: How to change a Module?
Thank you
Opti
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Use-case: for example: sortCol1: sort_by{|x| x[0] } # =>
(1..10).sortB; hash.sortB
···
Am 17.08.22 um 20:01 schrieb Die Optimisten:
Hallo
How can I add methods to Enuerable??
class Enumerable end # => TypeError: Enumerable is not a class ##
Yes, its a module...
I want to have a method which can be used by Array, Hash and Enum
likewise.
Maybe the question then is: How to change a Module?
Wolf
(Wolf)
4
Hallo
How can I add methods to Enuerable??
Would be nice if you would check your mail before sending it.
class Enumerable end # => TypeError: Enumerable is not a class ##
Yes, its a module...
I want to have a method which can be used by Array, Hash and Enum likewise.
Maybe the question then is: How to change a Module?
Did you try it? There is nothing special here:
/ # irb
irb(main):001:1* module Enumerable
irb(main):002:2* def foo
irb(main):003:2* puts "xx"
irb(main):004:1* end
irb(main):005:0> end
=> :foo
irb(main):006:0> .foo
xx
=> nil
W.
···
On 2022-08-17 20:01:16 +0200, Die Optimisten wrote:
--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.