`mymeth` worked fine for me. You’d have to invoke as `mymeth(var) {|e| ...}` of course (among multiple options) and ensure it has access to `arr` in its scope or declare `arr` as `@arr` if you are at the top level scope.
Regarding “I assumed arr.delete{} would delete if the expr is true. Would anyone expect what arr.delete is doing??”, what you are really looking for is: `arr#delete_if {}`
`arr.delete {}`’s block does something different. Here is what the Ruby API says: “ the result of the block is returned if the item is not found”
Andy
···
On Aug 11, 2021, at 2:35 PM, Die Optimisten <inform@die-optimisten.net> wrote:
Hello
Thanks for the answers!
How can I do it with an OPTIONAL blocK?
Meaning:
how can I forward the block as arg to another method?
def mymeth(var, &block)
arr.find (var, &block) ... # does not work! # how to "tranlate"
the args to use them here?
end
---
I assumed arr.delete{} would delete if the expr is true. Would anyone
expect what arr.delete is doing??
/"Would anyone expect what arr.delete is doing??/”
- I should have written: "/Does (could) //anyone expect what arr.delete
is doing??/”
Yes, mymeth works fine,
Would'nt a [normal/standard/non-programming ] human expect
[1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??
Should this be changed (Ruby7)?
Maybe thats not easy, because much SW may depend on this... [ we have
.delete !! ]
The (different) question is:
How can I transfer args (unknown if it's a block or a variable), for
example if writing an interface for .uniq:
myIndex ->{|args)|
puts 'Now running index'
self.index(args) # does not work (with a block)
}
myIndex.call(args)
Same with a method:
class Array #def myIndex(*args)
def myIndex(*args,&block)
puts 'Running index'
self.index(*args,&block)
end end
[3,3,4].myIndex{|x| 5} # -> 'given block not used' ???
···
Am 11.08.21 um 23:29 schrieb Andy Maleh:
`mymeth` worked fine for me. You’d have to invoke as `mymeth(var) {|e|
...}` of course (among multiple options) and ensure it has access to
`arr` in its scope or declare `arr` as `@arr` if you are at the top
level scope.
Regarding “/I assumed arr.delete{} would delete if the expr is
true. Would anyone expect what arr.delete is doing??/”, *what you are
really looking for is*: `arr#delete_if {}`
`arr.delete {}`’s block does something different. Here is what the
Ruby API says: “ the result of the block is returned if the item is
not found”
/"Would anyone expect what arr.delete is doing??/”
- I should have written: "/Does (could) //anyone expect what arr.delete
is doing??/”
Yes, mymeth works fine,
Would'nt a [normal/standard/non-programming ] human expect
[1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??
Should this be changed (in Ruby7)? -- We have .delete !!
Maybe thats not easy, because much SW may depend on this...
Question still open:
1) How can I transfer args (unknown if it's a block or a variable), for
example if writing an interface for .uniq or .index :
myIndex ->{|args|
puts 'Now running index'
args.index(&block) # does not work (with a [optional] block)
}
myIndex.call(args)
"Would anyone expect what arr.delete is doing??”
- I should have written: "Does (could) anyone expect what arr.delete is doing??”
Yes, mymeth works fine,
Would'nt a [normal/standard/non-programming ] human expect
[1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??
Should this be changed (in Ruby7)? -- We have .delete !!
Maybe thats not easy, because much SW may depend on this...
Question still open:
1) How can I transfer args (unknown if it's a block or a variable), for example if writing an interface for .uniq or .index :
myIndex ->{|args|
puts 'Now running index'
args.index(&block) # does not work (with a [optional] block)
}
myIndex.call(args)
Hello!
Good example
My answer:
We live in a linear world [it is already complicated enough...]
So when not writing [[2,3]] (as element), the solution must be [1,2,3,3]
Specification: elems.minus(elems)
(must be two arrays syntactically)
Cheers. Opti
···
Am 12.08.21 um 12:40 schrieb Matthew Kerwin:
On Thu, Aug 12, 2021 at 7:01 PM Die Optimisten > <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:
Would'nt a [normal/standard/non-programming ] human expect
[1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??
Hello!
Good example
My answer:
We live in a linear world [it is already complicated enough...]
So when not writing [[2,3]] (as element), the solution must be
[1,2,3,3] # wrong line pasted!!
If we leave the subject ...[REPLACES previous mail!],
then it doesn't make sense to post anything more...
···
Am 12.08.21 um 15:17 schrieb Die Optimisten:
Hello!
Good example
My answer:
We live in a linear world [it is already complicated enough...]
So when not writing [[2,3]] (as element), the solution must be [1,2,3,3]
Specification: elems.minus(elems)
(must be two arrays syntactically)
Cheers. Opti
Am 12.08.21 um 12:40 schrieb Matthew Kerwin:
On Thu, Aug 12, 2021 at 7:01 PM Die Optimisten >> <inform@die-optimisten.net <mailto:inform@die-optimisten.net>> wrote:
Would'nt a [normal/standard/non-programming ] human expect
[1,2,2,3,3,3] - [2,3] == [1,2,3,3] ??