Questions tagged [proc-object]
47 questions
2
votes
1 answer
proc changing class in irb
Just when I thought I had my head wrapped around procs & lambdas this happens...
irb> x = Proc.new{|name| "Hello #{name}"}
irb> x.class #=> Proc
irb> x.call("Bob") #=> "Hello Bob"
irb> x.class #=> String
irb> x #=> "Bob"
Why is x changing its class…

Paul
- 503
- 1
- 3
- 12
1
vote
3 answers
Unable to pass a variable to a procedure using upvar in Tcl
I need a procedure that will be able to access, read and change a variable from the namespace of the caller. The variable is called _current_selection. I have tried to do it using upvar in several different ways, but nothing worked. (I've written…

SIMEL
- 8,745
- 28
- 84
- 130
1
vote
1 answer
Using proc to duplicate parameters in Tcl
I want to make several objects, all with the same parameters, so I tried to store them in a proc that returns them. But the interpreter evaluates the returning result as one parameter, instead of several. my proc is:
proc element_param {} {
…

SIMEL
- 8,745
- 28
- 84
- 130
1
vote
2 answers
How do I call multiple procs?
I could use some help on this one, given this code:
result1, result2, result3 = do_stuff {
method_1
method_2
method_3
}
I would like to be able to write a method called do_stuff that can call each line of that block individually and return a…

efleming
- 247
- 2
- 4
- 9
1
vote
4 answers
Ruby - What is this output
I know that this code may be not quite correct:
def print_string(&str)
puts str
end
print_string{"Abder-Rahman"}
But, when I run it, this is what I get:
#
What is this output?

Simplicity
- 47,404
- 98
- 256
- 385
1
vote
4 answers
Using procs with Ruby's DSLs
For user convenience and more clean code I would like to write a class that can be used like this:
Encoder::Theora.encode do
infile = "path/to/infile"
outfile = "path/to/outfile"
passes = 2
# ... more params
end
The challenge now is, to…

GeorgieF
- 2,687
- 5
- 29
- 43
1
vote
3 answers
Ruby Proc Syntax
An answer to a question I posed yesterday on here was the following piece of Ruby code:
def overlap?(r1,r2)
r1.include?(r2.begin) || r2.include?(r1.begin)
end
def any_overlap?(ranges)
ranges.sort_by(&:begin).each_cons(2).any? do |r1,r2|
…

mbm
- 1,902
- 2
- 19
- 28
0
votes
3 answers
A method that applies self to a proc
I want to have a method defined on Object that takes a block and applies the receiver to the block. An implementation will be like the following:
class Object
def apply ≺ pr.call(self) end
end
2.apply{|x| x * 3} # => 6
Is there already a…

sawa
- 165,429
- 45
- 277
- 381
0
votes
2 answers
What is happening to this lambda ? could someone explain
proc_obj = -> proto { print proto; puts("World")}
puts proc_obj["Hi"]
puts proc_obj.call("Hello") #Is this is the same as above
please refer me to some link to demystify this ...

pankajdoharey
- 1,562
- 19
- 30
0
votes
2 answers
Yet another proc vs. lambda discussion
I thought when you called a proc within a method the return value of the proc would trigger a return from the out block context that called the proc. When I call test(a_block) I feel like the puts "after the block" should not be executed as there…

slindsey3000
- 4,053
- 5
- 36
- 56
0
votes
1 answer
Maple: Why I can not plot my function which is definrd by proc?
So I created a proc that returns a value. (sqrt analog that is correct for numbers from (2.1) and up). I can evaluate it for any given number but I cannot plot it. Why and how to fix it?
code (converted to 1-d math input):
>
restart:
…

Rella
- 65,003
- 109
- 363
- 636
0
votes
3 answers
how can I delegate a call passing through the block that came with it?
I'm traversing an object graph and want to pass it a block that will run on each node of the structure from a method - let's called visit.
At the top, I'm going to call with a block and I want to delegate the initial call to visit on the root object…

Dafydd Rees
- 6,941
- 3
- 39
- 48
0
votes
2 answers
Paperclip dynamic Proc styles called before object initialized
I have the following paperclip setup. What happens is that I'm using a proc to set the sizes for various styles. However, the proc gets called on new and during the super call. I walked through the debugger and it seems like it processes the :photo…

Bashir
- 21
- 4
0
votes
1 answer
Ruby Proc: Invoking method from Class A from within Class B, and using Class B's 'method'
I am not sure whether this is actually possible, but I wasn't able to find a clear answer anywhere. Also I find it hard to define my question in mere 'search terms'. So I am sorry if this has already been answered somewhere else, I could not find…

Michael van Rooijen
- 6,683
- 5
- 37
- 33
0
votes
2 answers
How can two arguments be passed to a method with a one-argument signature?
s = Proc.new {|x|x*2}
def one_arg(x)
puts yield(x)
end
one_arg(5, &s)
How does one_arg know about &s?

uzo
- 2,821
- 2
- 25
- 26