=> require 'facets/string/interpolate'
Hmm....
Very neat in application....
String.interpolate{a}
but....
def interpolate(&str)
eval "%{#{str.call}}", str.binding
end
...equally nasty in implementation.
Ah well, clearly then I wasn't missing something.... there is no
standard method.
Thanks,
John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand
···
On Thu, 28 Feb 2008, Trans wrote:
Guby
(Guby)
29 February 2008 12:21
2
Not that it is a lot nicer, but just another solution... and a little bit on side of what you wanted, but:
>> a = lambda{|c| "bra#{c}ket"}
>> a.call(" see ")
=> "bra see ket"
···
On Feb 28, 2008, at 12:42 AM, John Carter wrote:
On Thu, 28 Feb 2008, Trans wrote:
=> require 'facets/string/interpolate'
Hmm....
Very neat in application....
String.interpolate{a}
but....
def interpolate(&str)
eval "%{#{str.call}}", str.binding
end
...equally nasty in implementation.
Ah well, clearly then I wasn't missing something.... there is no
standard method.
Thanks,
John Carter Phone : (64)(3) 358 6639
Tait Electronics F
If you want it to look even nicer, write it like:
>> a = lambda{|c| "bra#{c}ket"}
>> a[" see "]
=> "bra see ket"
-Rob
···
On Feb 29, 2008, at 7:21 AM, Guby wrote:
Not that it is a lot nicer, but just another solution... and a little bit on side of what you wanted, but:
>> a = lambda{|c| "bra#{c}ket"}
>> a.call(" see ")
=> "bra see ket"
On Feb 28, 2008, at 12:42 AM, John Carter wrote:
On Thu, 28 Feb 2008, Trans wrote:
=> require 'facets/string/interpolate'
Hmm....
Very neat in application....
String.interpolate{a}
but....
def interpolate(&str)
eval "%{#{str.call}}", str.binding
end
...equally nasty in implementation.
Ah well, clearly then I wasn't missing something.... there is no
standard method.
Thanks,
John Carter Phone : (64)(3) 358 6639
Tait Electronics F
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
Guby
(Guby)
29 February 2008 17:31
4
Sweet, that looks better!
Good to learn something new!
S
···
On Feb 29, 2008, at 11:07 AM, Rob Biedenharn wrote:
If you want it to look even nicer, write it like:
>> a = lambda{|c| "bra#{c}ket"}
>> a[" see "]
=> "bra see ket"
-Rob
On Feb 29, 2008, at 7:21 AM, Guby wrote:
Not that it is a lot nicer, but just another solution... and a little bit on side of what you wanted, but:
>> a = lambda{|c| "bra#{c}ket"}
>> a.call(" see ")
=> "bra see ket"
On Feb 28, 2008, at 12:42 AM, John Carter wrote:
On Thu, 28 Feb 2008, Trans wrote:
=> require 'facets/string/interpolate'
Hmm....
Very neat in application....
String.interpolate{a}
but....
def interpolate(&str)
eval "%{#{str.call}}", str.binding
end
...equally nasty in implementation.
Ah well, clearly then I wasn't missing something.... there is no
standard method.
Thanks,
John Carter Phone : (64)(3) 358 6639
Tait Electronics F
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
7rans
(7rans)
29 February 2008 18:27
5
The only trouble here is that you get the binding of where you defined
the lambda, rather than the one in which you ultimately evaluate it
in.
With 1.9 I think we can use instance_exec to handle that however --
that being the case, the String::interpolate method I demoed above
could be improved.
T.
···
On Feb 29, 9:07 am, Rob Biedenharn <R...@AgileConsultingLLC.com> wrote:
If you want it to look even nicer, write it like:
>> a = lambda{|c| "bra#{c}ket"}
>> a[" see "]
=> "bra see ket"