ruby

Quick Advice: How should this be written in Ruby?

I am a Java/C++ programmer and Ruby is my first scripting language. I sometimes find that I am not using it as productively as I could in some areas, like this one for example: Objective: to parse only certain lines from a file. The pattern I am going with is that there is one very large line with a size greater than 15, the rest are de...

Ruby Enterprise 1.8.7 and standard Ruby 1.8 have overlapping gem paths

I installed Ruby Enterprise 1.8.7 on a Ubuntu server that already has the standard Ruby 1.8.6 install. They both put the same local user gem directory /home/{username}/.gem/ruby/1.8 in their GEM PATHS. Is this safe and proper? If not, is there a way to alter the GEM PATH of Ruby Enterprise 1.8.7 (but not Ruby 1.8.6) through an environm...

'sudo gem install' or 'gem install' and gem locations

running 'sudo gem list --local' and 'gem list --local' gives me differing results, my gem path is set to my home folder and only contain the gems from 'gem list --local'. So it's probably not good to have gems installed in different directories on my computer, should I have the gem path set differently? and should I always use sudo when...

Why does Ruby's ri not return to a bash command prompt (maybe Unix question)?

When I execute ri ... in a terminal on my Mac, I get, maybe, 50 blank lines, then the output I'm expecting, then a last line: (END) , with (END) displayed with white letters on black background. I am not returned to bash, however -- ri is still running, and I can't enter anything. Also, why all the blank lines? What's up? Cary ...

How can I nest this if/else as per Ruby?

I want to do this in ruby: something() if conditional else something_else() This doesn't compile, nor anything similar from what I tried. Is it possible to have statements in this format or do I have to do this as: if conditional something() else something_else() end ...

how to use nokogiri methods .xpath & .at_xpath

I'm learning how to use nokogiri and few questions came to me based on the code below require 'rubygems' require 'mechanize' post_agent = WWW::Mechanize.new post_page = post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708') puts "\nabsolute path with tbody gives nil" puts post_page.parser.xpath('/html/body/div/div/d...

Ruby: what method is called?

Assume, I have an object x of MyClass. What method is called, when I do puts x? I need to override it with my own one. I thought it was .inspect, but somehow overridden inspect isn't being called. For example, I have a class Sum: class Sum initiazlie a, b @x = a + b end end And I wanna access the result like this: s = Sum...

Worth learning Ruby if not using Rails?

Hello! So I took a quick look at Ruby some days ago. At first I was quite astonished by some things it features which really seem to make a programmers life easier. (Use of blocks, object model,...) But then there is this big problem: Nobody seems to be using Ruby without Rails! The #Ruby(-lang) channel is dead, people are only talking...

When and where do I require files in a rails application?

Let's say I have I have the following file in my lib directory of my rails application: #lib/proxy.rb module SomeService class ServiceProxy def do_something end end end If I want to use ServiceProxy in a model, I can use it like so: #app/models/product.rb require 'proxy' class Product < ActiveRecord::Base def do_someth...

How to surpress strange stdout message when using Ruby and SOAP

STDOUT is getting some strange output: ignored attr: {}abstract All of my SOAP calls are working fine but this is just annyoing my cron job :) Thanks ...

ruby mechanize: how read downloaded binary csv file

I'm not very familiar using ruby with binary data. I'm using mechanize to download a large number of csv files to my local disk. I then need to search these files for specific strings. I use the save_as method in mechanize to save the file (which saves the file as binary). The content type of the file (according to mechanize) is: ap...

How can I extract html escape chars/entities as text when scraping web? (ruby & nokogiri)

In my ruby+mechanize(nokogiri) script I use this piece of code: row.at_xpath('td[3]/div[1]/a/text()').to_s.strip on a forum where the post title html looks like: <a href="showthread.php?t=233891" >&lt;/body&gt; on Footer ?</a> and I receive from xpath this string &lt;/body&gt; on Footer ? I would like to get what I can see in ...

Using do block vs brackets {}

New to ruby, put on your newbie gloves. Is there any difference (obscure or practical) between the following two snippets? my_array = [:uno, :dos, :tres] my_array.each { |item| puts item } my_array = [:uno, :dos, :tres] my_array.each do |item| puts item end I realize the bracket syntax would allow you to place the block on...

How to restrict user access page in RoR?

I know that I can have a session after the user login. Also, I created a helper method called "current_user". I don't want to other people which are not signed in can get access to the page. Apart from making doing this, how can I do? I can do this to not allow people the get access to the content, but I don't want the user within login...

Complete Ruby on Rails tutorial

I'm new to RoR, but familiar with MVC, REST, used a lot Symfony, Yii, CI and other smaller php frameworks. Now I want to learn Ruby on Rails. Please help me find a complete tutorial for "dummies", which describes creating web application from scratch on RoR. This is like Symfony's Askeet and Jobeet tutorials. Thanks for any help! Upda...

Ruby Ebook for building social neworking site.

I want to build a basic Social networking site in Rails. Can you please suggest me some ebooks for that or any web resource. Thanks ...

Using a self-signed certificate

I am just trying to get my head around SSL. I have set up a Jetty server on my localhost, and generated my own certificate using Keytool. Now when I go to https://localhost:8443/ I get the can't trust this certificate error. I use keytool -export -alias pongus -keystore keystore -file certfile.cer To create the certificate whic...

Can't upload photo using paper clip in RoR

I use this code to upload photos, I find that it is not successfully upload photo, but other content can be updated. <% semantic_remote_form_for(@product, :html => {:multipart => true}) do |f| %> <% f.inputs do %> <%= f.input :title, :label => "Name" %> <%= f.input :category , :include_blank => false , :label => "Catego...

How can I identify and process all URLs in a text string?

I would like to enumerate all the URLs in a text string, for example: text = "fasòls http://george.it sdafsda" For each URL found, I want to invoke a function method(...) that transforms the string. Right now I'm using a method like this: msg = "" for i in text.split if (i =~ URI::regexp).nil? msg += " " + i else ...

Ruby obfuscator

Is there a ruby obfuscator or "compiler"? ...