ruby

Is there a location for custom Ruby libraries to be stored so Ruby can find them?

I have written a module that has some generic, reusable code that I would like to be able to use in other projects. Is there a place I could put this file on computer so that Ruby can find it regardless of where I saved the file that is including it? I am using a Mac. ...

no such file to load -- soap4r -- why?

I migrated to 1.8.7 Ruby and now I keep getting this error and it is driving me crazy. I try installing it manually using gem install soap4r and also include it as a config.gem 'soap4r' and rake gem:install and still nothing.... It's blowing up on my heroku install too.... ...

Sinatra app running on Heroku has RegexpError

My sinatra app runs fine locally but when I push it to heroku it crashes and I get this error RegexpError - undefined (?...) sequence: /(?<=(LIST ALL SELECTED ))\w/: The line of code where the occurs is match = data.match('(?<=(LIST ALL SELECTED ))\w')[0] What I am trying to do is capture the next letter directly after 'LIST ALL S...

Listing the latest unstable gem version?

When I do: gem search -r rails It shows me: rails (2.3.8) But how do I know the latest unstable version which is 3.0.0.rc so that I can use it: gem install rails --version=3.0.0.rc ...

how to pass parameters to an alias method in ruby

Hi All, I want to create a alias method in ruby and pass parameters to this. I managed to do the following class User def say_name puts "I'm sameera" end end class User alias :tell_name :say_name def say_name puts "I'm sameera gayan" tell_name end end user = User.new user.say_name and it gives me the out put a...

Help refactoring this code

Update: the much better answer has little to do with refactoring, but has to do with setting a default for empty keys. See the first answer- thanks a lot guys! Hi folks, how would you refactor this? if n=network_stats["b"] network_stats["b"] = n +1 else network_stats["b"]=1 end I have a nagging feeling this ...

downloading only the header of a file

I'm using mechanize for scraping a website which works nicely, however since you can't tell from a link what kind of file it is linking to e.g. http://somesite.com/images.php?get=123 is it possible to download only the header only? It doesn't have to use mechanize but is there any Rails way of doing this? ...

Downloading only the header of a file

I'm using mechanize for scraping a website which works nicely, however since you can't tell from a link what kind of file it is linking to e.g. http://somesite.com/images.php?get=123 is it possible to download the header only? I'm asking this because I'd like to decide based on the filetype if I will download it. Also it would then help...

Is it possible to use "eval" to define just one function (as opposed to one for each)?

Hi folks, today, i am defining a set of variables in a hash that I use in various functions all over the model and the controller. From the code below, you see that I am defining functions like get_stats, get_fans to target the exact variable. My question is, would it be possible to define just one function? NOW: REQ={:USER_STATS_I...

Mechanize in Jquery

I am adept in Ruby WWW::Mechanize. And I was wondering if a jQuery equilavent exists ? ...

Text files made in ruby are being built as executable files

Hi all. I have a build script where i create a text report file and output various log type stuff to it. The data is all being built onto an external hd which (according to 'mount') has file format "fuseblk" (which i've never heard of). The building all seems to work ok but my report files are being saved as executables, which linux...

Does the hoster has to support "Ruby on Rails" or "just Ruby" to run Rails?

Does the hoster have to support "Ruby on Rails" or "just Ruby" to run Rails? I know mainly PHP and ask myself if "Ruby on Rails" behaves to Ruby ... like "Zend Framework" to PHP: just a bunch of PHP files I can copy in my project folder and my hoster only needs to support PHP. I ask as my host only supports Ruby (but not Rails). If I c...

How do I convert a string text into a class name

I have a string as classname = "Text" using this I want to create an object of the Text class Now when I try doing this classname = classname.constantize I get the Text as a module and not as a class. Please suggest something. Thanks and regards Rohit ...

what `update_attribute` return if it get failed?

Hi All, I have following piece of code @user = User.find(params[:id]) if (@user.activation_status == "active") #some code here @user.update_attribute('activation_status' ,'inactive') # Line 44 #send mail to user that his account is Acivated else end Is there any chance that Line 44 get fail because of any reason (for e...

Find a process ID by name

How can I find a pid by name or full command line in Ruby, without calling an externally executable? In my example below, I am sending a SIGUSR2 to a process who's command line contained "ruby job.rb". I would like to do the following without the call to pgrep: uid = Process.uid pid = `pgrep -f "ruby job.rb" -u #{uid}`.split("\n").firs...

Is there any technique for profile testing application in isolation?

I am a dummy in profiling, please tell me what you people do to profile your application. Which one is the better, Profiling the whole application or make an isolation? If the choice is make an isolation how you do that? ...

Multilevel Hash Default Parameters When Accessing Non-Existant Keys as in h[1][1] += 1

I'm trying to create a Hash of Hash-es. The value of the 2nd level hash is an integer defaulted to 0. What I'm trying to do is start with an empty hash of hashes, and then when I add a value if the key doesn't exist, they key should be added with a default value. When I try this with a simple Hash of integers, it works fine: irb(ma...

Routing problem with cucumber

hello coders and codetts I am working with rails 3 and cucumber, all is going well except for this little problem Given I am on the "edit automobile" page No route matches {:controller=>"automobiles", :action=>"edit"} (ActionController::RoutingError) Now the path is set in paths.rb as edit_automobile_path and in the routes.rb I ha...

How to match unicode words with ruby 1.9?

I'm using ruby 1.9 and trying to find out which regex I need to make this true: Encoding.default_internal = Encoding.default_external = 'utf-8' "föö".match(/(\w+)/u)[1] == "föö" # => false ...

Textmate and Shoulda: how to run a focused test

TextMate has a command 'run focused test'. The command fails to recognize that the code is a test, it says "Error: This doesn't appear to be a TestCase or spec." Does anyone know how to run a focused test from textmate or a trick/hack to get around this problem? Thanks! ...