ruby

Strategy for reading a tab delimited file and seperating file for array with attr_reader

Hey everyone. Trying to take a simple test.txt file and seperate the text and integers after its read in for array manipulation. The idea is to be able to use/require the attr_accessor from the seperate Person class. So I can use :name, :hair_color, :gender For example lets says we have in our text file which is all seperated by the tab...

Strange behavior between rails and irb

If I drop in to irb and do require 'atom' I can successfully include the gem but if I try to include it in my controller in rails I get no such file to load -- atom when I visit the page in the browser. What's going on here? Here's the complete stack trace: C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_r...

How to save Rails log to database outside the application?

I'm trying to save the Production environment log to the database on other server.. What I mean that when some errors shown I want to open ssh and check the end of production.log.. What I want is to go to the other database (on other server maybe) ant check it out. I want the logged information to be the same as I see in the *.log, cont...

Object address in Ruby

Short version: The default inspect method for a class displays the object's address.* How can I do this in a custom inspect method of my own? *(To be clear, I want the 8-digit hex number you would normally get from inspect. I don't care about the actual memory address. I'm just calling it a memory address because it looks like one. ...

Joining arrays of hashes in Ruby

Hi. I am trying to join multiple arrays of hashes in ruby using a common key. For example: country_info = [ {country_id: "US", country_desc: "United States"}, {country_id: "AU", country_desc: "Australia"} ] country_stats = [ {country_id:"US", pageviews: 150}, {country_id:"AU", pageviews: 200} ] i_want = [ {country_id: "US",...

Avoiding protected level accessors and equality methods in Ruby testing

I have some Ruby code that uses protected level attr_readers to be able to implement an == method so that we can assert some resultant Calendar is equal to an expected Calendar), but those protected accessors would not be needed for any code besides assertions in test code. Some code I have looks like this: class Calendar def i...

Cucumber: Before hook run only once for all scenarios

I have a scenario outline with multiple scenarios. I'd like my Before hook to run only once so I can bootstrap the ActiveRecord objects I need to run against all of the scenarios. The problem is if I use Before do # my code here end This will execute before each Scenario. Is there anyway to run it once for the entire Outline? ...

Ruby: nested regular expressions and string replace

I'm using CodeRay for syntax highlighting, but I'm having trouble with this regular expression. The text will look like this: <pre><code>:::ruby def say_hello puts 'hello!' end </code></pre> This part: :::ruby will tell CodeRay which language the code block should be interpreted as (but it needs to be optional). So here's what I hav...

Devise: How to create a private admin role?

I have a simple Rails 3 blog app that needs an admin user so I can restrict creating and editing blog entries to the admin. I've used devise before, but only for users that are public and can be created by anyone. I don't want the ability to create an admin to be publicly accessible. How should I configure devise to be able to have an ad...

Simulating a directory tree platform-independently

I am using Qt and Ruby in an application where I have to manipulate some directories and rename/move files. However, prior to the actual manipulation I need to show a "preview", ie, simulation of the changes. What I've done on OS X and Linux is a collection of mkdir and touch commands, in a writable tmp space, to build my said "directory...

Problem installing gem on Windows Vista 32-bit

Good day. I have a problem installing the gem "showoff". For some reason it can't install. The error message is as follows: C:\Ruby>gem install showoff Building native extensions. This could take a while... ERROR: Error installing showoff: ERROR: Failed to build gem native extension. C:/Ruby/bin/ruby.exe extconf.rb checking...

How do I override initWithContentRect in MacRuby?

I want to override initWithContentRect on a subclassed NSWindow, as I've seen done in Obj-C, in order to create a borderless window from a nib. If I try this: class GroupWindow < NSWindow def initWithContentRect(contentRect, styleMask:windowStyle, backing:bufferingType, defer:deferCreation) super.initWithContentRect( conten...

Writing templates without using html for ruby on rails/django

I hate to explicitly use html/css to build pages. Is there a template language I can use to semantically and quickly describe the layout and content of the page so that later I can generate html and css from it? I'm planning to use this on a django site (but I guess if such solution already exists for RoR I can always adapt it). Thank...

difficulty modifying two dimensional ruby array

Hi there, Excuse the newbie question. I'm trying to create a two dimensional array in ruby, and initialise all its values to 1. My code is creating the two dimensional array just fine, but fails to modify any of its values. Can anyone explain what I'm doing wrong? def mda(width,height) #make a two dimensional array a = Ar...

Is there a Ruby, or Ruby-ism for not_nil? opposite of nil? method?

I am not experienced in Ruby, so my code feels "ugly" and not idiomatic: def logged_in? !user.nil? end I'd rather have something like def user.not_nil? end But cannot find such a method that opposites nil? ...

Ruby Mysql troubles

I have troubles with mysql gem installation. I performed this in my terminal: (I am using Mac OS X Snow Leopard) sudo env ARCHFLAGS="-arch i386" gem install mysql -- \ --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \ --with-mysql-include=/usr/local/mysql/include Password: Building native extensions....

How can I have a test unit in the same source file?

This question is Ruby related. Suppose I want to have the test unit for my class in the same file as it's definition. Is it possible to do so? For example, if I'd pass a "--test" argument when I run the file, I'd want it to run the test unit. Otherwise, execute normally. Imagine a file like this: require "test/unit" class MyClass en...

attr_reader with question mark in a name

Sorry for this, probably, really newbie question: I want to define a getter that returns bool value. f.i.: attr_reader :server_error? But then, how do I update it, as Ruby (1.9) throws syntax error if there is a question mark at the end: #unexpected '=' @server_error? = true self.server_error? = true ...

Delegating to the base class implementation

How can I delegate the invocations within a baseclass to the base class implementation rather than the inherited class implementation? For example: class A def foo p "hello" end def bar foo end end class B < A def foo p "world" end end A.new.bar # prints "hello" B.new.foo # prints "world" B.new.bar # prin...

How to create Windows Service using JRuby?

I know we can create windows service using win32-service gem which is available in Ruby. How we can create a windows service in JRuby, is there any java-specific way which can be re-used ?? ...