ruby

How do I access the value for this nested hash's key in Ruby?

I have the following hash: {:charge_payable_response=>{:return=>"700", :ns2=>"http://ws.myws.com/"}} How can I get the value of the key :return, which in this example is 700? ...

Complex Forms in rails (has_and_belongs_to_many)

Hello all - Right now, I'm in the middle of actually building a Project Management application, and I'm kind-of stuck on the way i should build this form. At the moment of adding a project I would like to select the clients that would be included in the project. Here's the code to a few things of interest: Project Model Project Migrati...

rake jobs:work working fine. problem with script/delayed_job start.

I am calling function with LoadData.send_later(:test). LoadData is my class and test is my method. It's working fine while i am running rake jobs:work. But when i am running script/delayed_job start or run that time delayed_job.log shows error like TEastern Daylight Time: *** Starting job worker delayed_job host:KShah pid:5968 TEaste...

cattr_accessor not working (outside rails) when active_support is required?

Hi guys, I'm not familiar with active_support, so bear with me! Fox's library allows searching via google's APIs, but it requires active support. i can't seem to get it working though! Any ideas? require 'rubygems' require 'active_support' require 'google_search' p GoogleSearch.web :q => "Hello World!" Gives me: NoMethodError: unde...

Ruby: What's going on here?

This question is based off some really odd code I recently found in a colleagues work. He claims not to know how it works only he copied it from somewhere else. That's not good enough for me I want to understand what's going on here. Say we have something like (test1, test2, test3="3", test4="4") the result will be that test1 == "3",...

Semicolon in object variable name

There's a common LDAP attribute called userCertificate;binary. It actually has a semi-colon in the attribute name. In ruby, I turn an LDAP entry into a OpenStruct object called 'struct'. >> struct.class => OpenStruct But of course ruby thinks it's an end-of-line character. ?> struct.userCertificate;binary NameError: undefined loc...

Compiling a library for Ruby with SWIG on Mac OS X

I tried to compile the following library and everything went smooth until the last step. /* File : computation.c */ int add(int x, int y) { return x + y; } /* File: computation.i */ %module computation extern int add(int x, int y); $ swig -ruby computation.i $ gcc -c computation.c $ gcc -c computation_wrap.c -I/opt/local/lib/ruby/1....

Active Mailer doesn't have the application helpers when used with delayed_job v.2

So if I try sending an email with action mailer directly, I can use all application helpers like url_for, content_for etc, but when I try to do the exact same action [sending email] with delayed_job [send_later] I getting a delayed job fail, of undefined function content_for etc, so it is like no helpers are loaded in my ActionMailer. I ...

Why Eventmachine Defer slower than Ruby Thread?

I have two scripts which using mechanize to fetch google index page. I assuming Eventmachine will faster than ruby thread, but not. Eventmachine code cost "0.24s user 0.08s system 2% cpu 12.682 total" Ruby Thread code cost "0.22s user 0.08s system 5% cpu 5.167 total " Am I use eventmachine in wrong way? Who can explain it to me, ...

Can Ruby Fibers be Concurrent?

I'm trying to get some speed up in my program and I've been told that Ruby Fibers are faster than threads and can take advantage of multiple cores. I've looked around, but I just can't find how to actually run different fibers concurrently. With threads you can dO this: threads = [] threads << Thread.new {Do something} threads << Threa...

Rubyists: What is this called?

Say I have a pool of enumerables that I want to group by an attribute: cars = Car.all.group_by(&:color) Then I want to iterate over those cars like so: cars.inject([]) do |stack, (color, cars)| stack << cars.each do |car| ... end end What is the term for the block variable extension (between the parentheses)? ...

Blocks and Yields in Ruby

I am trying to understand blocks and yields and how they work in Ruby. How is a yield used and most of the rails applications use yields in a weird way. Can someone explain to me or show me where to go to understand them. ...

ruby1.9.1 can't find installed gems, yet ruby1.8 can...

On ubuntu here. I installed both ruby1.8 and ruby1.9.1. I also ran these commands ruby1.8 setup.rb ruby1.9.1 setup.rb Both worked fine, I was also able to install gems for both. The gems in gem 1.9.1 and gem1.8 both show up correctly for gem list. The problems however begin with this: ruby1.9.1 some_script.rb. It cannot find any of th...

how to remove html element's style attribute using Hpricot?

like this: <p style="font-size: 12pt;"> Hello world <span style="font-weight: bold;">just do it</span> </p> I want to remove every element's "style" attribute. I want the result like this: <p>Hello world <span>just do it</span></p> how to do this using hpricot? thanks. ok I have solved this like below: doc = Hpricot("<p st...

[Ruby] [gem] A GEM error shown during run the commend: gem update --system

I’m a freshman on Ruby and now trying to install ruby on my machine according to the Tutorial on http://wiki.openqa.org/display/WTR/Tutorial However, after I installed the ruby186-26, and run the command “gem update --system”, the following error occurred: C:\Documents and Settings\e482090\Desktop>gem update --system c:/ruby/lib/ruby/s...

General question about Ruby singleton class

module MyModule def my_method; 'hello'; end end class MyClass class << self include MyModule end end MyClass.my_method # => "hello I'm unsure why "include MyModule" needs to be in the singleton class in order to be called using just MyClass. Why can't I go: X = MyClass.new X.my_method ...

What is the limit of Sinatra?

I've been learning the Ruby web framework Sinatra lately, and I'm finding it great to use. Most of the articles and blogs I have read about it seem to assume that it is good only for small websites, or 'tiny' web-apps. Is this true? Can a complete web application be built in Sinatra, or is Ruby on Rails the way to go? ...

0 before the number

hi, i have an int. i want print it in this format: ex. 1 -> 000001 15 -> 000015 How can i do? thanks ...

How can I export a rails model to json schema?

I am looking to optimize how we build forms for some of our models and ideally I would like to build them from json-schema. Is there a gem or the like which would allow me to export a model definition to json-schema? Bonus: With validations. Bonus: While modelling association relationships. ...

whats wrong with this ruby hash?

I'm pretty new to ruby, I keep getting the following error: in gem_original_require': ./helpers/navigation.rb:28: odd number list for Hash (SyntaxError) Any help appreciated... module Sinatra::Navigation def navigation @navigation nav = { primary[0] = { ...