ruby

Automatic input in Ruby script?

Im running this command from ruby script: system "trad install" This will prompt me three times for choosing y/n. Is there a way to automatically choose y,y,n? ...

Processing multiple JSON Objects in one file

I did something stupid... I gathered a big tonne of json data and saved it in one file. I now find myself getting errors when I try JSON.parse(file) due to the fact that its JSON object after JSON object. Can anyone advise on how I can parse this data? The strcture looks as follows. The next entry is a object with the exact same structur...

Groups have no effect with Bundler

Hi! I'm using Bundler gem 1.0.0.rc.6 and Rails 2.3.8 I specified a gem to be part of the production group in the Gemfile but, when I run a Rails console in dev env, that damn gem is loaded! I strictly followed the setup found on http://gembundler.com/v1.0/rails23.html Any idea ? Thanks ! Edit: BTW the 'problematic' gem is not loaded...

Current folder name in Ruby?

Is there a simple way to get the name of the current folder name or do I have to do it with regexp? ...

LoadError: no such file to load -- serialport

I have the serialport gem installed so I'm thinking there is something wrong with my paths. which ruby /usr/local/bin/ruby which gem /usr/local/bin/gem Also, it looks like I have two different versions of serialport gem: ruby-serialport-0.7.0 serialport-1.0.4 Could this be an issue? Also here is the error I got: Boot Error Som...

Snippets/examples for practical rubyish design patterns?

I wonder if there are Ruby snippets for various design patterns you can use in Ruby. Examples: Builder method Declare ghost methods Using blocks for DSLs (like Rails) So that one doesn't have to reinvent the wheel. Im not talking about books, but a collection of ruby snippets for various practical things, nothing abstract and gener...

Where i put my module/class in ROR MVC architecture

Hello all, I have made a module named module ConstantModelName AIRPORT = "Airport" end It contains all the constant values used in my application. So where should i place this module in my application. currently i placed it in lib folder in my app. Give your valuable comments. Thanks ...

What does ; mean in Ruby?

I am trying to learn how to write plugins in Rails by learning other people's plugins, turns out it is way harder than I thought. I found this: module Facebooker class AdapterBase class UnableToLoadAdapter < Exception; end What does the fourth line: class UnableToLoadAdapter < Exception; end mean? What is the best book to learn...

Possible to call executable Thor-powered script without calling thor?

I have a thor-based Ruby script, but I want to deploy it as a gem in people's bin directories that people can hit without having to do thor mytool. So instead they'd just use mytool Is this possible? I know it's possible with vanilla optparse but I'd rather use Thor if possible. Update: This is the code I'm using based on the example...

Master-Detail on RoR with Ajax

What is the best pattern to do a master-detail form in Ajax using RoR? My form has an order and for each order there is a lot of itens. I want to do only one form where the user can set the order details and include, exclude and update itens. When the user insert an item, I am doing an AJAX call to my controller so the user can search fo...

Is it allowed to write code without method enclosure in a class / module? what does this code mean?

For example a file in active_support/core_ext/exception.rb it started with: module ActiveSupport if RUBY_VERSION >= '1.9' FrozenObjectError = RuntimeError else FrozenObjectError = TypeError end end Then continued with class Exception code what does it mean? What do you use FrozenObjectError, RuntimeError, and TypeError...

How to be an independent Ruby programmer

I am tired of asking unanswered questions when using many outdated plugins / gems, and sometimes they don't really work how I really wanted. So my question is simple: If I was a PHP programmer, and Rails was my first framework, what do I need to learn next so I can depend on myself when working with troublesome plugins or code snippets...

Ruby on Rails: Learning ActionController class - Question on $:.unshift activesupport_path and autoload method

Hi, Inside ActionController class (rails/actionpack/lib/action_controller.lib) I found several weird code. I don't really have a mentor to learn Ruby on Rails from, so this forum is my only hope: Question #1: Could anyone help me explain these lines of codes? begin require 'active_support' rescue LoadError activesupport_path = "#{...

Matching everything between two specific words using regular expressions

I'm attempting to parse an Oracle trace file using regular expressions. My language of choice is C#, but I chose to use Ruby for this exercise to get some familiarity with it. The log file is somewhat predictable. Most lines (99.8%, to be specific) match the following pattern: # [Timestamp] [Thread] [Event] [Message...

How to debug a plugin / gem? (with useful notes to setup and use ruby-debug gem)

Is there a way like how we debug models / controllers with logger.debug? Or even a better method? Thank you! Edit 1 Using ruby-debug seems like a steep learning curve for me, could anyone point me something similar to logger.debug, perhaps? Edit 2 Alright, I think I started to get a grasp on ruby-debug. Some useful notes for newbie...

problem with rake task.

While running rake task with parameters i am getting this problem. C:\projects\Test1>rake test_rake_task csv_header csv_column (in C:/projects/CyncErp) ** Invoke annotate_models (first_time) ** Execute annotate_models krunal get_model_names model_name = csv_header model_name = csv_column rake aborted! Don't know how to build task 'csv_h...

How to debug a plugin or gem using ruby-debug gem, where the part I wanted to debug started from test scripts?

For example I have this gem called Authlogic-openid, that plugin is outdated, no longer supported, and broken (let me know if you know any alternative by the way). I wanted to make sure the test runs by keying ctrl+R on vendor/gems/authlogic-oid-1.0.4/test/acts_as_authentic_test.rb [Please do not attempt to try my steps below, the gem ...

When using the $1-$9 regular expression form, why does calling gsub(...) on one nil the others?

First, a working example: string = "foo-bar-25-baz" if string =~ /(.+)-(10|25)(?:-(baz))?/ puts $1 puts $2 puts $3 end This produces 'foo-bar', '25' and 'baz' on three lines, as expected. But if we do this: string = "foo-bar-25-baz" if string =~ /(.+)-(10|25)(?:-(baz))?/ puts $1.gsub('-', ' ') # Here be the problem puts $2...

How to check if a string is base 64 encoded in Ruby?

I have to implement some code in Ruby based on Java implementation that was already done in the company. Parts of the Java code has the usage for checking if a string is base64 encoded using Base64.isArrayByteBase64(aInput) from org.apache.commons.codec.binary.Base64 library. I did see that the Ruby's standard library includes a module...

Decrypt AES-256-EAX encrypted string in Ruby?

I need to decrypt a AES-256-EAX encrypted string from Java in Ruby. Ruby's built-in OpenSSL::Cipher provides functionality to decrypt AES-256-CBC, when I try to use AES-256-EAX, its throwing that the algorithm is not supported. Is there any library/gem out there that decrypts AES-256-EAX string in Ruby? Thanks in advance. ...