On Mon, Feb 18, 2013 at 1:05 PM, Joel Pearson <[email protected]> wrote:
> Nice tips! Thanks for the help again.
You're welcome.
> I had no idea how to use to_enum, I'll have to read up on that. I've
> done all the Ruby courses I could find at Codecademy which filled in a
> few gaps I had in my knowledge. I'm still reading the Book of Ruby as
> well.
Basically that method stores self and method name along with arguments
given in a new object which implements #each as delegation to the
method stored and also includes Enumerable. You can cook your own for
learning purposes
E = Struct.new :obj, :method, :arguments do
include Enumerable
def each(&b)
obj.send(method, *arguments, &b)
self
end
end
irb(main):017:0> s = "foo bar"
=> "foo bar"
irb(main):018:0> e = E.new s, :each_char
=> #<struct E obj="foo bar", method=:each_char, arguments=nil>
irb(main):019:0> e.map {|x| "<#{x.inspect}>"}
=> ["<\"f\">", "<\"o\">", "<\"o\">", "<\" \">", "<\"b\">", "<\"a\">", "<\"r\">"]
Note that #map is defined in Enumerable
> I've decided to leave the "Matrix" class name alone in case I need to
> use it within the same scope later. I've renamed this "RubyExcel" for
> want of a better term.
+1
> I've added the ability to upload a multidimensional array into the data.
> It carries the option to overwrite or append as a switch.
Two remarks:
- don't catch the exception inside the method
- better create two methods - one for overwrite and one for append
(even if they internally delegate common work to another method)
This will give you a clearer API. See here for more reasoning:
http://stackoverflow.com/questions/1331630/use-method-flag-or-new-method#answer-1598344
> I've added "find" to return a "cell address" when given a value
You may also want to add #select etc. Or you include Enumerable and
implement #each as delegation to the Hash's #each and get #select and
all others for free.
> I still have a long list of things I want to add, and I'm sure I'll
> think of more. I'm surprised I haven't found anything equivalent out
> there, to be honest. Maybe all the real pros are using databases to
> parse their output :p
:-)
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
--
[email protected] |
https://groups.google.com/d/forum/ruby-talk-google?hl=en
---
You received this message because you are subscribed to the Google Groups
"ruby-talk-google" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.