ruby

Is there such a thing as a constant instance variable in Ruby?

My googlefu sucks and was unable to find information on this. Basically I want to have a instance variable that is visible only within the scope of a class/module but is also immutable. I am new to Ruby and apologize if this question doesn't make much sense. ...

In Ruby, if a hash is not going to be needed later, is it better to use hash.merge!({...}) instead of hash.merge({...}) ?

This happens in Ruby on Rails's View, where there is a hash for another partial. This hash has about 20 key/value pairs. There is (in HAML) - if (some_conditon) = render :partial => 'some_name', :locals => a_hash.merge({ :extra => true }) - else -# a lot more processing, including concatenating the partials and return as json - ...

closing windows shell after rake execution

Hello there, I need to execute a rake task in a windows machine and unfortunately to do so I have to open a shell. How can I close it once the task has been completed? system('start rake db:MyTask') Thanks,. ...

Organizing a bunch of controllers that all deal with the same model

I have a bunch of different controllers that all deal with the same basic model. For example... FoobarController FoobarShareController FoobarTakeController FoobarToolsController FoobarVerifyController They all do various things to the foobar model and I kind of wanted a better way to organize them along with other things that deal w...

Easy way to rename rails controllers

Is there an easy way to rename a controller? The only way I know of is to either do it by hand or generate a new controller move the code over and destroy the old one. Seems like there has to be a programmatic way to do this. ...

How can I get a lazy array in Ruby?

How can I get a lazy array in Ruby? E.g., in Haskell, I can talk about [1..], which is an infinite list, lazily generated as needed. I can also do things like iterate (+2) 0, which applies whatever function I give it to generate a lazy list. In this case, it would give me all even numbers. Anyway, I'm sure I can do such things in Ruby, b...

Callbacks with Scripting Bridge?

I'm using Ruby to check the position of videos I'm playing in Quicktime via Scripting Bridge. At the moment I'm just checking the position like so every n seconds: require 'osx/cocoa' include OSX OSX.require_framework 'ScriptingBridge' app = SBApplication.applicationWithBundleIdentifier_("com.apple.QuickTimePlayerX") while true ap...

MongoMapper - manually setting an ObjectId failing with "illegal ObjectID format"

I've got a simple model object: class UserRating include MongoMapper::EmbeddedDocument key :idea_id, ObjectId key :rating, Integer end I'm trying to set an Idea_Id on this object with: user_rating.idea_id = ObjectId.new This throws: "illegal ObjectID format" This sure seems like simple code... The only oddity I am noticing ...

How can I get source code of a methods dynamically and also which file is this method locate in

I would like to know whether I can get source code a method on the fly, and whether I can get which file is this method in. like A.new.method(:a).SOURCE_CODE A.new.method(:a).FILE ...

Best way to manage Rails application configuration settings persisted in a database?

Hello, I was hoping someone could suggest some best practices for configuring Rails applications using a database (i.e. persisting configuration settings to a database rather than a flat file). My reasoning for this is that I have an application that will run on multiple servers and there are some configuration settings that are fairly ...

OData Provider in Ruby/Java

Are there any OData provider SDKs for Ruby or Java? ...

Simple printing key of a hash?

Hi, I want to print a key from a given hash key but can't find simple solution myhash = Hash.new myhash["a"] = "bar" # not working myhash.fetch("a"){|k| puts k } # working, but ugly if myhash.has_key("a")? puts "a" end Any other way? tnx ...

Ruby on Rails private link sharing: Google Docs Style

What would be the best way to go about giving users the ability to share a private link that enables anyone who clicks it to view a certain page/document/item that have privacy restrictions in place? In my case: A User creates events which are limited to certain groups of relationships in the database (namely: friends, friends of frien...

How to freeze gems in a Ruby application?

Hello, I am playing around with ruby and making my first desktop app. I have used 2 gems for my app and to make my "application" portable, I need to freeze those 2 gems and make my project refer to those gems from its project folder. I know many ways to do it on Rails, but how to do it manually in Ruby? Note: I am using jeweler using ...

undefined method `destroy_unused' for Tag(id: integer, name: string):Class

I'm currently using acts_as_taggable_on_steroids on Rails 2.3.8. After configuring the plugin, when i try to destroy a post with a tag, it gives me this error: undefined method `destroy_unused' for Tag(id: integer, name: string):Class Do i have to redefin a destroy method in my Posts controller? I'm stumped, any help would be apprecia...

How to do it in Ruby on rails

This is a C# code: byte[] pb = System.Text.Encoding.UTF8.GetBytes(policy.ToString()); // Encode those UTF-8 bytes using Base64 string policyB = Convert.ToBase64String(pb); // Sign the policy with your Secret Key using HMAC SHA-1. System.Security.Cryptography.HMACSHA1 hmac = new System.Security.Cryptography.HMACSHA1(); hmac.Key = Syste...

TypeError: wrong argument (String)! (Expected kind of OpenSSL::Digest::Digest)

I have a problem with Ruby's openssl library. Here is what I do: In my Rails application, I start the "./script/console", then type: >>OpenSSL::HMAC.hexdigest('sha256','','') gives me this error: TypeError: wrong argument (String)! (Expected kind of OpenSSL::Digest::Digest) from (irb):15:in `hexdigest' from (ir...

Ruby FLVTool2 is no longer working

Hi guys, Our website allow video upload; clients were able to download videos from youtube, upload them on our website, then FLVTool2 (ruby) is used to process the videos. This tool was working for couple of years, but now it gives me some errors due to the new youtube encoding. the error I have is ERROR: EOFError ERROR: /usr/lib/ru...

The email body is missing when I send mails with attachements using ActionMailer

The content in the view is not being displayed. Only the attachment is being sent. Help would be appreciated! def send @subject = "Status of PIS App" @recipients = "[email protected]" @from = APP_CONFIG[:email] @sent_on = Time.now #@content_type = "text/html" content_type = "multipart/alternative" attachment :filename => "Report.ht...

Drag and drop ala GMail a gem for Ruby / Rack?

Is there a widget or a gem which implements this feature? It works only in Chrome and Firefox but it is very cool and no plugins are needed http://gmailblog.blogspot.com/2010/04/drag-and-drop-attachments-onto-messages.html Or which would be the best practises to implement it? ...