ruby

What type of applications should I build using Ruby?

I just move my experience on C# into Ruby. Ruby is very interesting programming language, I really like it. I do know Rails is a web application framework that are used by lots of web developers and uses Ruby language. What else of applications should we build on ruby? ...

if i like Ruby a lot, is there a reason I should learn another language now, such as Lua or Erlang?

if i like Ruby a lot, is there a reason I should learn another language now, such as Lua or Erlang? ...

Performance comparisons of Frameworks to Use for an Auction Web Site

I am a Java guy and therefore would prefer a Java based framework for an auction site that I am planning to develop from scratch. But all my colleagues and friends have pointed out to me that the better sites that are coming up now-a-days are mostly written either using Ruby on Rails, Django or ASP.net MVC framework. I was wondering ...

Why is ruby so much slower on windows?

What are the specific technical causes of Ruby being so much slower on Windows? People report about a 3X speed drop from Linux/OSX and there are some vague discussions about Ruby using a compiler for Windows versions that produces slow code but I can't find any specific details. Anybody know the specifics? I'm not interested in hurf d...

How do I use a Rack middleware only for certain paths?

I'd like to have MyMiddleware run in my Rack app, but only for certain paths. I was hoping to use Rack::Builder or at least Rack::URLMap, but I can't quite figure out how. This is what I thought would work, but doesn't: # in my rackup file or Rails environment.rb: map '/foo' do use MyMiddleware, { :some => 'options' } end Or, bett...

Sorting a Ruby array

I am trying to sort large inputs in the fastest way in ascending order. The code is something like this: t=gets ti=t.to_i r=[] for i in(0..ti) k=gets r[i]=k.to_i end r.sort_by{|x| -x.last} This is giving me an error saying undefined method 'last' for nil:nilclass <nomethoderror> from tsort.rb: in sort_by from tsort.rb in 'each...

Custom RESTful route within has_many nesting

Projects have many tasks and a task has a custom RESTful action called 'approve'. I'm expecting the helper to look something like this approve_project_task_url This isn't working for me: map.resources :projects, :has_many => :tasks, :member => { :approve => :post } ...

Ruby, Source Code of Splat?

Someone asked about the splat operator yesterday, and I wanted to see the source code... would that be written in C or in Ruby? Where would it be found? ...

Ruby experts: can you help/suggest with improving this line of ruby code?

After spliting a tab delimited file I have my required values in a string variable. Unfortunately the source of this file is out of my control. Here are three exact example of what the value might hold: " 5.344" " -2.345" " -.977" Notice the white space, no '0' prefixing the decimal points and the double quotes are in the string. O...

How can I convert an entire line of input into an integer in Ruby?

I want to give integer input to Ruby like this: 12 343 12312 12312 123123 231 12 343 12312 12312 123123 243 12 343 12312 12312 123123 2123 This whole thing should be taken as a number so that I can sort all of them and if there is any repeating numbers I want to print them. The whole line should be treated as an integer for compariso...

How can I take a specific number of lines of input in Ruby?

I am taking inputs in Ruby like this: lines = STDIN.readlines.map{|x| x.strip.to_i}.sort This takes input from the command prompt, but I want to take input a specific number of times. Suppose my number of test cases is 3, how can I stop it after 3 lines of input? ...

Which international city has the most Ruby on Rails jobs?

I would like to ("need to" might be a better way of putting it) move to a city where I have a better chance of finding my first Rails job. Within the United States, my best guess is maybe San Francisco. Outside the US I have no idea, although I want to avoid countries where wages would not be on a par with the US. How could I determin...

Can I override task :environment in test_helper.rb to test rake tasks?

I have a series of rake tasks in a Rakefile which I'd like to test as part of my specs etc. Each task is defined in the form: task :do_somthing => :environment do # Do something with the database here end Where the :environment task sets up an ActiveRecord/DataMapper database connection and classes. I'm not using this as part of Rai...

undefined params and session hashes in before_filter

Does anybody know why, when using ruby-debug by calling debugger in a method called as a before_filter, the params and session hashes are not defined? class MyExampleController < ActionController::Base before_filter :test_hashes def test_hashes pp session pp params #both work as expected.. debugger #calling the ...

Is it possible to create a list of months between two dates in Rails

I am trying to create a page to display a list of links for each month, grouped into years. The months need to be between two dates, Today, and The date of the first entry. I am at a brick wall, I have no idea how to create this. Any help would be massively appriciated Regards Adam ...

Format text for STDOUT in Ruby

Hello, I am writting a small Ruby script that will run in a CLI. To improve the interface, I need to would love to add color/boldness to some elements that I output. Is that doable? If so (and I am almost sure this is), how? Thanks a bunch ...

Integrating Ruby Handler With Apache

If you use Webrick you can implement a servlet and service http requests using ruby. Now I have code that does everything that I want but I would like to move to Apache. Is there a way to modify the .htaccess file to send all the requests through a ruby handler? ...

[Ruby] Converting Array of Strings to Array of Floats

Hi there. I'm writing an app that revolves around getting sets of numerical data from a file. However, since the data is acquired in string form, I have to convert it to floats, which is where the fun starts. The relevant section of my code is as shown (lines 65-73): ft = [] puts "File Name: #{ARGV[0]}" File.open(ARGV[0], "r...

Running Ruby scripts under JRuby/Rack as if they were CGIs

Is there a way to map *.rb files to be executed under JRuby with the output being sent out to the browser like a CGI? Basically I'm looking for a JRuby CGI servlet. Ideally, I'd like to define a JRuby servlet in web.xml and then be able to put *.rb files in WEB-INF/ruby and be able to call them via http://servername/contextname/rubypro...

web development with ruby without rails?

For reasons beyond my control, I'm being tasked with Ruby web development that does NOT use Rails or really any other heavyweight framework such as Merb. I'm wondering if anybody else has encountered this and can recommend best practices or resources that describe best practices for such a problem. I'd like to avoid the dreaded out.p...