rbjl
August 6, 2010, 9:41pm
1
Hi, I’ve collected some nice little additions to Ruby and put them in a
gem called zucker.
Some of the features:
control structure like iteration:
iterate [1,2], [3,4,5] do |e,f|
puts “#{e},#{f}”
end
outputs
1,3
2,4
,5
/Ruby\d/ | /test/i | “cheat”
creates a Regexp similar to:
/(Ruby\d|[tT][eE][sS][tT]|cheat)/
Blocks, where nil can be egocentric
egonil do
nil.some_methods.that[:do].not.exist
end # => nil
[1,2,3].map &[:*, 5] # => [5, 10, 15]
What’s your opinion about these methods?
J-_-L
rbjl
August 7, 2010, 5:05am
3
On Aug 6, 2:41 pm, Jan L. [email protected] wrote:
Hi, I’ve collected some nice little additions to Ruby and put them in a
gem called zucker.
I was going to give it a try, but when I installed it (sudo gem
install zucker), I only ended up with the /var/lib/gems/1.8
directories and none of the /usr/lib/ruby/1.8/ directories.
I’m running Linux Mint 9.
$ gem -v
1.3.5
$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
rbjl
August 7, 2010, 10:00pm
4
On 08/06/2010 12:41 PM, Jan L. wrote:
outputs
Blocks, where nil can be egocentric
What’s your opinion about these methods?
I like the way you think These feel like a natural progression,
although I
admit the array to proc is a bit hacky (but useful).
Mike
rbjl
August 8, 2010, 12:28am
5
Thank you all for your feedback
Benoit D. wrote:
I extended a bit the concept to allow multiple syntax:
Classes/to_proc.rb at master · eregon/Classes · GitHub
I would not use any of these for serious code, however.
I like the chaining idea
@yermej Looks like if something is wrong with your Rubygems
installation. Did you install it from the repositories or from source?
J-_-L
rbjl
August 7, 2010, 1:11pm
6
Hi,
On 6 August 2010 21:41, Jan L. [email protected] wrote:
outputs
1,3
2,4
,5
[3,4,5].zip([1,2]).each { |e,f| puts “#{f},#{e}” }
would do the same (the reverse order is needed to get the extra value).
It is definitely better looking than something like Vector#each2,
though.
/Ruby\d/ | /test/i | “cheat”
creates a Regexp similar to:
/(Ruby\d|[tT][eE][sS][tT]|cheat)/
Looks like syntactic sugar. I would need a real use-case to see if it
is really better. You can already do something like this:
case str
when /Ruby\d/, /test/i, “cheat”
end
Blocks, where nil can be egocentric
egonil do
nil.some_methods.that[:do].not.exist
end # => nil
[1,2,3].map &[:*, 5] # => [5, 10, 15]
That is rather cool !
I extended a bit the concept to allow multiple syntax:
# A little #to_proc craziness
# Ideas came from many places
# Mainly http://rbjl.net/29-become-a-proc-star
class Array
def to_proc
if Array === first
if size == 1
procs = first.map(&:to_proc)
Proc.new { |obj|
procs.map { |sub| sub[obj] }
}
else
procs = map(&:to_proc)
Proc.new { |obj|
procs.inject(obj) { |result, sub|
sub[result]
}
}
end
This file has been truncated. show original
I would not use any of these for serious code, however.
What’s your opinion about these methods?
J-_-L
Some nice hacks and ideas. I guess some real examples would help to
see the utility of it.
rbjl
August 8, 2010, 2:10am
7
On Aug 7, 5:28 pm, Jan L. [email protected] wrote:
installation. Did you install it from the repositories or from source?
J-_-L
Yeah, looks like something is wrong with my machine. I’ve used gems in
the past on this machine, but I must have broken something.