ruby

JSON object for just an integer

Silly question, but I'm unable to figure out.. I tried the following in Ruby: irb(main):020:0> JSON.load('[1,2,3]').class => Array This seems to work. While neither JSON.load('1').class nor this JSON.load('{1}').class works. Any ideas? ...

building sorted sections from map

I have unsorted map of key value pairs. input = { "xa" => "xavalue", "ab" => "abvalue", "aa" => "aavalue", "ba" => "bavalue", } Now I want to sort them by the key and cluster them into sections by the first character of the key. Similar to this: output1 = { "a" => { "aa" => "aavalue", "ab" => "abvalue", }, ...

How to extract a single character (as a string) from a larger string in Ruby?

What is the Ruby idiomatic way for retrieving a single character from a string as a one-character string? There is the str[n] method of course, but (as of Ruby 1.8) it returns a character code as a fixnum, not a string. How do you get to a single-character string? ...

Ruby/Rails and Sharepoint Web Services

I'm trying to consume Sharepoint webservices with ruby. I've basically given up trying to authenticate with NTLM and temporarily changed the Sharepoint server to use basic authentication. I've been successful getting a WSDL using soap4r but still cannot authenticate when attempting to use an actual web service call. Has anyone had any...

What are the Ruby Gotchas a newbie should be warned about?

I have recently learned the Ruby programming language, and all in all it is a good language. But I was quite surprised to see that it was not as simple as I had expected. More precisely, the "rule of least-surprise" did not seem very respected to me (of course this is quite subjective). For example: x = true and false puts x # displ...

Dir.glob doesn't work on site hosted by site5?

Hi, I have uploaded some files to a directory under public and I try to access them using Dir.glob. But I get no results back. The Dir.glob works fine on dev server (mongrel) and also works fine when using script/console on the site installed on site5 is there a way to get this working or a different way to get the list of files? ...

Better ruby markdown interpreter?

I'm trying to find a markdown interpreter class/module that I can use in a rakefile. So far I've found maruku, but I'm a bit wary of beta releases. Has anyone had any issues with maruku? Or, do you know of a better alternative? ...

Purpose of "consider_all_requests_local" in config/environments/development.rb?

What is the purpose of this Rails config setting... config.action_controller.consider_all_requests_local = true It's set to true by default in config/environments/development.rb. Thanks, Ethan ...

In Ruby, what are the best packages for decoding, encoding?

I am trying to encode/decode MIME headers in Ruby. ...

CouchDB + Datamapper + View = no ids

I'm using couchdbx v. 0.8.1 and datamapper 0.9.8. I've written a few simple views, copied some from other examples. If I query the views with a browser they return id's. If I query them using datamapper in ruby I get no id's. I've googled for days, been on IRC and looked through the couch and datamapper google groups. I've tried downgrad...

Add records from external ruby script

What is the best way to add records to a database from an external script. I would like to use activerecord but I'm not sure how to do so outside the rails directory structure. ...

Importing a huge csv data file and using the header to access columns using Ruby.

I need to import a huge csv data file (6880 columns) and I need to be able use the column headers to access it. What's the best way? Speed isn't important. Clarity is. ...

Get Filename from file path in Ruby

Hi, How can I get the file name from a file path in Ruby? For example if I have a path of "C:\projects\blah.dll" and I just want the blah. Is there a LastIndexOf function in Ruby? Thanks Paul ...

How can you conditionally remove entire columns from a two dimensional array in Ruby?

I have several large csv files with thousands of columns that I need to import and then remove entire columns based contents of the column. Is there an easy way to handle this in Ruby? I could transpose the data and then just delete rows but I was wondering if there was a more syntactically sugary way of doing it. ...

Looking for an easy templating solution with ruby

Hello, I am looking for a simple templating solution for ruby, i.e. something that will let me write php-like or jsp-like templates (html with embedded code tags), but in ruby. jsp is no good for me, because most hosting services (I'm on dreamhost) don't support it on their default package, and it's a little cumbersome to set up. php is...

A couple of questions on the architecture of Ruby

I am primarily a fluent .NET developer (as can be seen from the amount of posts and threads I make about .NET), but I thought it would be good to learn RoR. In doing so, I have a few questions about the architecture of the language (Ruby) and the framework (RoR): 1) In .NET, every object is derived from System but inherits System.Objec...

Ruby classes inheritance or whatever problem

my ruby (on rails) class looks like: class Foo def self.method1 someAction end def self.method2 someAction end def someAction //doSmth end end any ideas how to make this work or achieve the same behavior some other way? thanks! ...

How to parse word documents with ruby?

Does anyone know of a library that I can use on OS X/Linux to parse Word files and output the content as HTML? I've had a look at win32ole but as far as I can see it's for Windows only, although I could be wrong. Any suggestions? ...

How do I get ruby to print a full backtrace instead of a truncated one?

When I get exceptions, it is often from deep within the call stack. When this happens, more often than not, the actual offending line of code is hidden from me: tmp.rb:7:in `t': undefined method `bar' for nil:NilClass (NoMethodError) from tmp.rb:10:in `s' from tmp.rb:13:in `r' from tmp.rb:16:in `q' from ...

Rails - Multiple top level domains and a single session/cookie

Hello all, I've been struggling with this for quite awhile and haven't been able to find a solution. I need a user to be able to view multiple top level domains with a single login. My understanding is that this needs to be set in environment.rb and called with before_dispatch. This is what I've come up with: require 'activesupport' r...