I have found a CSV parsing issue with FasterCSV (1.5.0) which seems like a genuine bug, but which I'm hoping there's a workaround for.
Basically, adding a space after the separator (in my case a comma) when the fields are enclosed in quotes generates a MalformedCSVError.
Here's a simple example:
# No quotes on fields -- works fine
F...
I was asked to write a Perl-to-Python and Perl-to-Ruby (and vice versa) code translator by an evil boss, and therefore I'm curious to know if some automatic code translators between them exist already. Just by googling it, I found Perthon, plus endless discussions and dead projects trying to do this.
In your opinion, is there a standard...
I think in something like this:
def self.obj_list(opts = {:include => [] , :exclude => []})
# Returns an array with all objects with roles applied
# +:exclude+:: (array,string) optional object type to exclude from list
# +:include+:: (array,string) optional object type to include in list
# Example:
# Role.obj_list(...
lotofxpath = arrayofmanyxpaths.map{|s| "\"" + s + "\""}.join(",")
puts lotofxpath #=> "/html/body/a[1]", "/html/body/a[2]"
newb = doc.xpath(lotofxpath).to_a
this will not work, and complain about invalid xpath.
however, copying pasting the output string
newb = doc.xpath("/html/body/a[1]", "/html/body/a[2]").to_a
will work wit...
Hello,
I am a fresher as far as Ruby is concerned. i worked in PHP for sometime. I was wondering if there is some pakage like LAMP or WAMP as in case of PHP for Ruby too......
If not at least suggest me the best setup or IDE for Ruby
Thanx in advance
...
shepherd has_many animals. I am trying to clone one of them:
dolly=shepherd.animals.build(sheep.clone)
I get error:
undefined method `stringify_keys!' for #<Sheep:0xb6ce154c>
why? what is another way to clone dolly so that she would be associated with a shepherd and have sheep's attributes?
...
I've got some ruby code that I'm converting to Ruby 1.9. One warning I get is Hash#index is deprecated; use Hash#key
But Hash#key is not defined in Ruby 1.8, so I can't use that directly. Does anybody have a good alternative?
I've got a couple of options (which I'll post as answers so you can vote), but I'm hoping for better.
...
I'm confused, I have @quote.quote_line_items and this is an array of items like this:
[{id: 85, part_number: "X67AC0M08", short_description: "X67 Threaded Caps M8, 50 pieces", list_price: "18.00", arg_cost: "12.15", long_description: "X67 Threaded Caps M8, 50 pieces", created_at: "2009-11-27 20:29:58", updated_at: "2009-11-27 20:29:58",...
I can't seem to find the answer to this,
I somewhat see what it does through implementation, but don't grok the sense of it..
...
On Win32, I wonder how to detect whether Left Shift or Right ALT is pressed using Perl, Python, or Ruby (or even in C)?
Not just for the current window, but the global environment overall. Example: when I am typing a document, I can press Right ALT to start the music player written in Ruby, and then press Right ALT again and it can p...
when looping through many web pages and calling something simple like below
manyhtmlpages.each do |page|
doc = Nokogiri::HTML(page)
puts doc.xpath("/html/body/h2[1]","/html/body/a[1]").to_s
end
i observe that memory consumption continually goes up until the script terminates due to running out of memory.
when i remove the doc.xpa...
I found startling difference in CPU and memory consumption usage. It seems garbage collection is not happening when i run the following nokogiri script
require 'rubygems'
require 'nokogiri'
require 'open-uri'
def getHeader()
doz = Nokogiri::HTML(open('http://losangeles.craigslist.org/wst/reb/1484772751.html'))
puts doz.xpath("html[1]...
hi
i'm having a little trouble with closures and i'd like to know what
the equivalent code for the canonical make-adder procedure would be in
ruby,
in scheme it would be like
(define (make-adder n)
(lambda (x) (+ x n))
thanks in advance
...
is there a problem with doing? will there be some constraint on resources?
#main.rb
(1..100000).each do |loop|
`ruby dosomething.rb`
end
The reason i am doing this is because main.rb needs to be run in Jruby.
Somescript.rb runs faster using less resource in just Ruby, hence i am running it as shell command.
...
i need a way to run following nokogiri script
#parser.rb
require 'nokogiri'
def parseit()
//...
end
and call the parseit() while running below main.rb in jruby
#main.rb
require 'parser'
parseit()
Of course the problem is jruby cannot find 'nokogiri' as I have not installed it aka nokogiri-java via jruby -S gem install nokogiri
T...
A web app that launches cpu intensive background jobs in the background whenever users call it.
example: youtube.com. people upload videos, it gets converted in background job.
how can you deal with many users simultaneously attempting to launch their own background jobs ? it must be queued correct?
additionally, if the background job...
I have been reading a lot about Ruby the past few days. Every SO post I come across I hear that ruby is an elegant language. Can you guys give an example of why ruby is elegant compared another language?
...
Hello,
I have a newbie question!
I want to do something like this:
puts Example.new([a,b,c])
and the result to be
=> a,b,c
I tried something like this:
class Example
attr_accessor :something
def initialize(something)
@something = something
puts @something
end
end
It works but not how I want it!
Thank you!
...
How I can get from a module the Class name of the class the module is included ?
module ActMethods
def some_method(*attr_names)
cls = self.class # this doesn't work
end
end
How I can get into the cls variable the name of the class to with this module is loaded ?
...
I don't know if this is a ruby question or a Sinatra question, because I'm new to both. The following code does not work, and I understand why, because the first my_variable is local to its block. I just don't know the syntax for getting it right.
require 'rubygems'
require 'sinatra'
configure do
my_variable = "world"
end
get '/...