ruby

Is it possible to compile Ruby to byte code as with python?

In Python if i want to give out an app without sources i can compile it in bytecode .pyc, is there a way to do something like it in ruby? ...

Auto complete an array according a vector

Hi, I have an array of 16 squares and I would like to auto complete it with integers values depending of the position in the array and the vector TOP_RIGHT. TOP_RIGHT = 3 # Build the array... @top_right = Array.new(16, 0) @top_right.each_index do |square| @top_right[square] = square / TOP_RIGHT if (0...16).include?(square - TOP_RIGH...

Rollback Ruby Version on Windows

How do you rollback from Ruby 1.9 to Ruby 1.8 ? ...

Is file still being uploaded?

I have an app that I'm writing that takes files in a specific directory that have been uploaded via SFTP and moves them to S3. I have a problem where my cron job starts uploading a file when it's not completely uploaded. I have thought of every way to try and wait until the file is complete, but I have no way of knowing (that I know of)...

Searching Hpricot with Regex

I'm trying to use Hpricot to get the value within a span with a class name I don't know. I know that it follows the pattern "foo_[several digits]_bar". Right now, I'm getting the entire containing element as a string and using a regex to parse the string for the tag. That solution works, but it seems really ugly. doc = Hpricot(open("ht...

ruby oneliner vs groovy

i was going through railstutorial and saw the following one liner ('a'..'z').to_a.shuffle[0..7].join it creates random 7 character domain name like following: hwpcbmze.heroku.com seyjhflo.heroku.com jhyicevg.heroku.com I tried converting the one liner to groovy but i could only come up with: def range = ('a'..'z') def tempList ...

Does any one know good editor available in RoR for windows?

Does any one know good editor available in RoR for windows? ...

Config.gem in test and cucumber environments

With RSpec and Cucumber, why is it preferred to specify :lib => false in the environment files - and then explicitly require the gems in spec_helper.rb and env.rb? ...

how to set color in ruby pdf-writer

Hi folks. I'm using pdf-writer gem in ruby. While drawing a table, i need to set the shade_color and shade_color2 of table so that the rows get the alternate shade and shade2 colors. Can anyone tell me how to set them? Like table.shade2 = Color::RGB::Magenta But i have a hexa vaue like 989898. Now, how to use this. Any help is appr...

Calling a method on a Ruby module

I have the following Ruby code: module MyModule class MyClass def self.my_method end end end To call my_method, I enter MyModule::MyClass.my_method. I'd like to write a wrapper for my_method on the module itself: MyModule.my_method Is this possible? ...

How to add cell-padding or cell-spacing in ruby pdf-writer

Hi folks, I have seen an ocean of options in pdf-writer Simple-Table, but it doesn't seem to have the cell-spacing and cell-padding. 1) Is it implemented, did i miss it? If so, can you plz gimme a line of code. 2) If not implemented, is there any work-around? Any help is appreciated. THanks ...

textile and maruku problem

Hi, all. I've developed custom filters for HAML (http://github.com/alec-c4/cb-haml-filters) and have a small problem with textile and maruku. Maybe you can help me with this Problem with textile with code %h2 Textile test :cbtextile h4. YouTube video http://www.youtube.com/watch?v=0_IXrjqKbE4&feature=player_embedded ...

Ruby to_proc hack with binding

I'm trying to create a little Ruby hack to make something like the reverse of the Symbol#to_proc hack. Whereas the Symbol#to_proc hack makes this possible: some_array.each(&:some_method) is the same as some_array.each { |obj| obj.some_method } I want to make this possible: some_array.each(&[:some_method]) would be the same as ...

How do I print output of exec() in realtime?

I am running the following (backup) code in a Ruby script: for directory in directories print `s3sync.rb --exclude="#{EXCLUDE_REGEXP}" --delete --progress -r #{directory} my.amazon.backup.bucket:#{directory}` end I would like the output of the executed subprocess to be echoed to the terminal in real time (as opposed to having to ...

Can you show me a quick working snippet to solve this command line option case?

I'd like to be able to support something like this when running my script from the command line: script.rb -n 2 -t first.txt -t second.txt I'd like to be able to take 1 or more t switches, but I have no clue how to achieve this. I would like to not have to do this: script.rb -n 2 -tfirst.txt,second.txt Got any ideas? ...

Missing elements in an Ruby on Rails Array

Hi, i despair in case of an array. I put some data into an array, but when i iterate the array some elements of the array seems to be missed, but the missing element are displayed in the view. I'm using the Plugin Rails_Authorization. my Code: def index if !params[:task_id] #Tasks der 1. ebene anzeigen, auf die der User zugr...

accessing third-party ruby library module in code? is this the right way on windows?

I needed a little script to read data out of windows-style .ini files. Searching my windows machine I found inifile.rb in this path: C:\ruby\lib\ruby\site_ruby\1.8\vr\contrib\ it seems unnatural to add this path directly to my rubylib path as this will mean any other special units I want will need to be added. so in my code I wrote...

Prototype, periodically_call_remote, updated content disappears when new link is clicked and lags.

Hi, periodically_call_remote is a great rails feature, but with ease comes novices so here I am. I have a div that is getting updated with content every 5 seconds. Looks great and was easy to setup. This page is the homepage so people will not be staying here long. So when they click another link, such as link_to "All Products", perio...

Rails Fixtures not loading with rspec

So, I'm trying to learn the rspec BDD testing framework in the context of a rails project. The problem I'm having is that I can't, for the life of me, get my fixtures to load properly in rspec descriptions. Disclaimer: Yes, there are better things than fixtures to use. I'm trying to learn one thing at a time, here (specifically rspec)...

What does Ruby constant mean?

What does Ruby constants really mean? The following code doesn't show any 'constant' attribute. The warning is there, but I still get to change what A refers to. A = 1 puts A # => 1 A = 2 # warning: already initialized constant A puts A # => 2 Or is Ruby constants are just an indication without any enforcement? ...