#apache #archlinux #asterisk #centos #debian #gentoo #haskell #kde #kubuntu #lisp #math #mysql #perl #python #ruby-lang #rubyonrails #suse #ubuntu #vim #wikipedia 0 1 2 3 4 5 6 7 8 9
Top Prev 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 Next
#ruby-lang
<LoganCapaldo> johnjosephbachir, for instance variables you don't generally need eval
<LoganCapaldo> obj.instance_variable_set("@a", value) obj.instance_variable_get("@a")
<LoganCapaldo> and avoiding eval if possible is usually a good thing
<johnjosephbachir> LoganCapaldo: i think it might be a rails-specific issue
<johnjosephbachir> LoganCapaldo: what's the better way to generate code?
<Olathe> # Don't leave me here with my restless lobster #
<LoganCapaldo> well it depends on what you are doing
<LoganCapaldo> but generally use a combo of define_method, send, include, extend, etc.
<LoganCapaldo> Basically the only thing you really _need_ eval for is mutating local variables
<LoganCapaldo> Or if you are gonna write irb
<johnjosephbachir> LoganCapaldo: that's what i'm doing, writing a patch for irb.
<johnjosephbachir> but thanks for the tips
<johnjosephbachir> know any good tutorials or books about ruby code generation and the like?
<LoganCapaldo> johnjosephbachir, http://redhanded.hobix.com/bits/evalLessMetaprogramming.html
<cored> imperator wasn't you a Perl guy ?
<johnjosephbachir> LoganCapaldo: looks great, thanks
<cored> imperator i think i remember your nickname from #perl
<imperator> cored, a long time ago, in a galaxy far, far away
<cored> hehehe
<cored> ok
<imperator> i used to hang out in #perl for a while anyway, but not really any more
<cored> i see
<imperator> cored, just joining us?
<cored> is there an easy way in Ruby to handle a CSV file, ala AWK ?
<cored> imperator more or less
<rixxon> csv file?
<cored> rixxon Comma Separated Values
<LoganCapaldo> cored: require 'csv'
<LoganCapaldo> although I would recommend gem install fastercsv
<cored> LoganCapaldo standard lib
<LoganCapaldo> yes
<LoganCapaldo> csv is in the standard lib
<cored> oki
<rixxon> File.read(foo).split(',') # ??
<cored> i have to compare two csv files, in fact two columns specified from the command line
<LoganCapaldo> rixxon, erm the format is a little more complicated
<rixxon> heh
<LoganCapaldo> but only a little
<rixxon> like, escapes? :)
<mirzapirza__> i need to load a meg or two of dictionary words and then check a bunch of random characters to see if there are any words there
<mirzapirza__> i was using a hash that uses symbols as keys.. @dict[word.strip.to_sym] = true
<mirzapirza__> and it loads some 170k words just fine, but after checking a bunch ( @dict[word.strip.to_sym] == true ) it started giving false positives, i think
<mirzapirza__> would there be a better way to do this? store the words in some other way? a different lookup approach?
<rixxon> why not an array
<rixxon> and why .to_sym, anyway
<mirzapirza__> i figured a hash might be faster than array.include?
<rixxon> perhaps
<mirzapirza__> to_sym would compare faster, right? only checks reference, rather than char-by-char
<rixxon> still has to convert anyway
<mirzapirza__> true true
Previous Page Next Page