ruby

Manually adding a Ruby Gem

I am trying to install the mechanize gem that is supposed to work with 1.9 from here: http://github.com/kemiller/mechanize but I do not know how to add it manually. I am using Windows, I could just copy the folder to the gems directory, but how do I initialize it? ...

KirbyBase and utf-8 string fields

I store utf-8 strings in KirbyBase table but later when I check string value encoding it is specified as IBM437. I'd like to have all strings stored in utf-8. Is this possible? Now when I have something like this: table.insert(some_utf8_string) table.select(:recno) { |r| r.utf8_field == some_utf8_string } select query doesn't find r...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can't see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a scenario where collection_select is better than select? or is anything I am missing here? ...

Ruby parser in Java

The project I'm doing is written in Java and parsers source code files. (Java src up to now). Now I'd like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses Ruby source code. The only thing I have been able to find up to now are Ruby parsers in Ruby (ParseTree and RubyParser...). I could maybe ...

Provide value for self when using Proc#call

When using Proc#call to call a lambda function in Ruby, self always ends up with the value that it had when the function was defined, rather than the value it has when the function is called, for example: $p = lambda { self } class Dummy def test $p.call end end d = Dummy.new > d.test => main Calling test returns main, when...

What's the difference between Ruby and JRuby?

Can anyone please provide me in layman's terms the difference between developing a JRuby and a Ruby, Rails application? I use NetBeans as my Ruby on Rails IDE and every-time I create a project is asks me that question - and I don't really get the difference. Are there any pro and cons? ...

ruby: what does the asterisk in "p *1..10" mean

the line p *1..10 does exactly the same thing as (1..10).each { |x| puts x } which gives you the following output: $ ruby -e "p *1..10" 1 2 3 4 5 6 7 8 9 10 it's a great shortcut when working with textmate for example, but what does the asterisk do? how does that work? couldn't find anything on the net... ...

http server validation

Hello, I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing for http protocole and specialy for the server part. Is there a test tool for verify that ? (no secret : http://raubarede.homel...

Encode a String in Ruby on Rails

How can I encode a string (iso to utf-8 for example) in Ruby on Rails, using Ruby 1.8.7 ? ...

How do I change the priority of a process via Ruby

Hi, When I exec a Ruby process, how can I have that process lower it's priority? I've looked at the documentation for Process.setpriority but I just don't get it. Does anyone have an example of how a Ruby process would lower it's own priority? Chris ...

Problem with stylesheet_link_tag

I have add stylesheet link tag to my application. I'm sure its worked. because in another place is working. but if I run at my computer it did not working. I mean my application cant load css when I seen at view source the result is : <script src="http://localhost:3000//javascripts/application.js?1258048544" type="text/javascript"></sc...

How can I run a controller method as a background task?

I've heard of the various background task tools (delayed_job, starling, workling, etc) but from looking at those it seems they're really only capable of running model-based methods (User.update_counters, for example). I need to be able to run a controller method as it's a pretty complex set of tasks that's intertwined a slew of other co...

Using rails 'vendor' folder for third party plug-in

I have a small third party flash application I'd like to incorporate in my rails app, but I am struggling to get it working properly. I believe it belongs in vendor opposed to lib, correct? Let's say I want the flash app to be loaded in my users controller in the signature action, how would I go about loading it in there. The app has m...

How to view/save/load work space in ruby's interactive mode

Hi, I need an interactive environment to play with some algorithm stuff. I want to be able to view what's been defined (data, function) so far and be able save/load so I can continue from a previous saved snapshot if something went wrong. Since I chose ruby as my main scripting language, I hope it had these features built in. If ruby in...

Howto fake a hash index?

Program I'm making has a simple configuration file looking something like this. @overlays = { :foo => "http://www.bar.com", :bar => nil, } What I need to do is go through this hash and get the following output. OverlayKey[0]='foo' OverlayVal[0]='http://www.bar.com' OverlayKey[1]='bar' OverlayVal[1]='nil' In order to keep my con...

Ruby Configure IRB to Pretty_Inspect by Default

Hi Guys, I'm fairly new to ruby, and am configuring IRB. I like pretty print (require 'pp'), but it seems a hassle to always type pp for it to pretty print it. What I'd like to do is make it pretty print by default, so if i have a var , say, 'myvar', and type myvar, it automatically calls pretty_inspect instead of the regular inspect...

Regular expression with pipe

It seems to me that | has a special meaning in regular expression world. I am using ruby and could not find much documentation on same. http://rubular.com/regexes/11724 works. http://rubular.com/regexes/11725 does not work. Why and what is the correct regex. ...

Multiple webs on a server using capistrano

Is there any way to configure Capistrano for deploying many webs on a server? I would like to have a project on port 80 an other project on port 1000 and manage each one with different dbs. ...

what is the best way to convert a json formated key value pair to ruby hash with symbol as key?

I am wondering what is the best way to convert a json formated key value pair to ruby hash with symbol as key : examole: { 'user': { 'name': 'foo', 'age': 40, 'location': { 'city' : 'bar', 'state': 'ca' } } } ==> { :user=>{ :name => 'foo', :age =>'40', :location=>{ :city => 'bar', :state=>'ca' } } } Is there a helper method can do t...

Question regarding rails migration and synchronizing views

I am a Rails beginner and trying to understand how rails migration works. I have created a scaffold like: script/generate scaffold Item col1:string col2:text rake db:migrate I would like to add another col4 using migration: I created a migration as follows: class AddCol4 < ActiveRecord::Migration def self.up add_column ...