proc-object Questions
8
I'm trying to use Ruby 1.9.1 for an embedded scripting language, so that "end-user" code gets written in a Ruby block. One issue with this is that I'd like the users to be able to use the 'return' ...
Encroachment asked 24/2, 2010 at 11:15
7
Solved
Joe Van Dyk asked the Ruby mailing list:
Hi,
In Ruby, I guess you can't marshal a lambda/proc object, right? Is
that possible in lisp or other languages?
What I was trying to do:
l = la...
Boffa asked 23/8, 2008 at 4:22
3
Solved
proc = Proc.new do |name|
puts "Thank you #{name}!"
end
def thank
yield
end
proc.call # output nothing, just fine
proc.call('God') # => Thank you God!
thank &proc # output nothing, to...
Lopsided asked 4/8, 2010 at 15:15
5
Is it possible to convert a proc-flavored Proc into a lambda-flavored Proc?
Bit surprised that this doesn't work, at least in 1.9.2:
my_proc = proc {|x| x}
my_lambda = lambda &p
my_lambda.lam...
Euphonium asked 1/6, 2010 at 0:13
3
Solved
I've got a variable that I would like to use as default value for an argument:
proc log {message {output $::output}} {
....
}
Is there a way to do this or need I to evaluate the variable inside...
Apothecary asked 23/6, 2011 at 9:53
5
Solved
I recently tried to do something akin to this:
a = "some string"
b = Proc.new{ upcase }
a.instance_eval b
Which gives the error:
TypeError: can't convert Proc into String
but this works:
d...
Unison asked 16/6, 2011 at 13:24
2
Solved
I'm new to programming, and ruby is my first real run at it. I get blocks, but procs seem like a light method/function concept -- why use them? Why not just use a method?
Thanks for your help.
Acetanilide asked 18/3, 2012 at 20:8
4
Solved
This article mentions 4 ways to invoke procs in ruby 1.9, and === is one of them. I don't understand why this would be done this way at all. Does it have any relationship to the normal meaning of =...
Palecek asked 12/3, 2012 at 21:1
3
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...
Gonion asked 6/3, 2012 at 20:13
3
Solved
The break statement for blocks (as per The Ruby Programming Language) is defined as follows:
it causes the block to return to its iterator and the iterator to return to the method that invoked ...
Boscage asked 17/1, 2012 at 2:28
2
Solved
in all the tutorials for RoR I see instances where the coder chose to use Proc.new when seemingly it is both unnecessary and rather unattractive.
Example, here is a callback for placed in a model,...
Mccorkle asked 1/3, 2011 at 22:32
3
Possible Duplicate:
What's the difference between a proc and a lambda in Ruby?
When run this Ruby code:
def func_one
proc_new = Proc.new {return "123"}
proc_new.call
return "4...
Quass asked 12/8, 2011 at 16:19
2
Solved
I lifted the following example from Josh Susser
def strip_accents params
thunk = lambda do |key,value|
case value
when String then value.remove_accents!
when Hash then value.each(&thunk)
...
Raincoat asked 10/3, 2011 at 16:32
4
Solved
Say I have a proc and the proc consists of several statements and function calls. How I can know how much time the function has taken so far?
Flexuous asked 9/3, 2011 at 7:30
1
Given the following method that takes one argument:
def foo(arg); p arg; end
I can call it with an empty array:
foo([])
# prints []
I can also save it as a Method object and call that with an...
Pasadis asked 18/1, 2011 at 7:59
1
Solved
In Ruby, are there any differences between Proc.new { 'waffles' } and proc { 'waffles' }? I have found very few mentions of the second syntax.
From testing using irb, I haven't found any obvious d...
Camphene asked 17/1, 2011 at 6:28
3
Solved
def foo
f = Proc.new { return "return from foo from inside proc" }
f.call # control leaves foo here
return "return from foo"
end
def bar
b = Proc.new { "return from bar from inside proc" }
b...
Eaglewood asked 16/9, 2009 at 22:3
4
Solved
I want to be able to write a lambda/Proc in my Ruby code, serialize it so that I can write it to disk, and then execute the lambda later. Sort of like...
x = 40
f = lambda { |y| x + y }
save_for_l...
Anastase asked 14/10, 2008 at 0:44
1
© 2022 - 2024 — McMap. All rights reserved.