ruby

Using Nokogiri and XPath to get nodes with multiple attributes

I'm trying to use Nokogiri to parse an HTML file with some fairly eccentric markup. Specifically, I'm trying to grab divs which have both ids, multiple classes and styles defined. The markup looks something like this: <div id="foo"> <div id="bar" class="baz bang" style="display: block;"> <h2>title</h2> <dl> List of stu...

Production usage of compiling Ruby Red to javascript

There has been a lot of discussion over this ability (such as in this SO question, or this github thread) to compile ruby to Javascript. The original version of Red is quite old, but Julius Eckert seems to have picked it up and made it far more usable (and even presented it) After seeing the community backing up compiling other language...

which applications made with Ruby?

hi Can I make a windows application with Ruby? what famous software made with Ruby (on or off the rails :D)? everybody seems to be talking about Ruby , and I need a motivation to learn it. ...

Is there a Javascript template system that wraps HTML?

I wonder if there are anything like a Javascript template system that wraps HTML, so that we don't have to deal with HTML directly (yeah, i know it's a bad idea, but just out of curiosity). So instead of writing HTML: <body> <div id="title">Great work!</div> <span>My name is Peter</span> </body> We write in Json: body: [ {div:...

Javascript wrapper that gives us Rubyish Javascript?

Are there any frameworks/wrapper out there that gives us rubyish javascript? Instead of the usual for() {} loop gives us the object.each {} loop like in Ruby? Since javascript could be used in web browsers I do want to use it for the server side too, but I do like ruby syntax far more. ...

Getting 2d array maximum in a more Rubyish way?

Background: In Ruby I have a 2d array like the following: count[[english_word, french_word]] = ... pp count {["my", "une"]=>0.0, ["my", "voiture"]=>0.2, ["red", "maison"]=>0.9, ... } (The reason I did this rather than count[english_word][french_word] was I wasn't sure how to get around the Undef errors, and I saw this syntax suggest...

Any chance that ruby could be used on client side?

For scripting on web browsers, the only option now is using javascript. I wonder if Ruby ever could make it to the web browsers? It's highly unlikely cause MS doesn't have any reasons for letting Ruby to become first class citizen, wouldn't that be bad for their current platform? I don't know how Apple sees it. If Ruby can't be first ...

Json(/hash) to ruby object?

In Javascript you can access json as objects. person = { name: { first: "Peter", last: "Parker" } } person.name.first In ruby I have to use it like this: person[:name][:first] Is it possible to access json (and hash) as an object just like in javascript? ...

How to use i18n_routing gem with rails2

Hello all, I installed the following gems in addition to rails 2.3.5: i18n (0.4.1) i18n_routing (0.3.7) In environment.rb I added require i18n_routing Inserted the following lines in routes.rb: map.localized(I18n.available_locales, :verbose => true) do map.resources :users map.resource :contact end but when I restart the se...

Ruby - determine if a number is a prime

I'm running through the problems on Project Euler to teach myself Ruby programming. I know there is a built-in function to do this, but I'm avoiding the built-in functions to help me learn. So I have to write a method to determine if a number is a prime. The first method works, but the second doesn't. Can anyone explain why? def is...

Ruby require path

Hi guys, My question is the following: I have a small Ruby code with different classes in a few files. In one of these file, I instantiate an object of the main class to start the execution. So this file as to require my other classes. (subquestion: is it a good way to start a ruby code ?) But I have a problem when I run the code fr...

Store with encryption and access a lot of big data using ruby

Which options do I have if I need to store a lot of files or big data chunks with encryption, access them fast and have it all in one file? Something like Sqlite with encryption and optimized for big chunks of data. Also I need ruby binding. ...

Displaying RoR relationship

I have setup a model relationship and all is working well when I use code similar to: @parent.child.each do |item| item.name end But how would I call just a specific child given there id eg. Child ID is 14 Would like a call like: @parent.child[childid].name #>>>>>> CHILD'S NAME ...

How do I parameterise RSpec tests so I can test the same behaviour under slightly different conditions

I'm implementing a service that has several different ways it can be accessed: Using simple query parameters With parameters encoded as a Javascript object For some calls both GET and POST are supported, with POST being used when there is large amounts of data being sent to the service. What's the best way to structure my RSpec test...

Importing issues for products

Ok so I am trying to import a csv which I need to insert into a db through rails or anyway that would be quickest so i decided to create a dummy rails application to do the importing. Here is some of the code below which I got some of it from a blog I was reading. def upload table = ImportTable.new :original_path => params[:upload][:c...

Sorting Items in Rails Controller Method

I'm having an issue writing a controller action that takes Post ids passed as a parameter and sorts them into a specific order before publishing them. The Posts have a position attribute (I'm using acts_as_list for sorting), and are either published or unpublished (searchable with the named_scopes Post.published and Post.unpublished, ac...

Calling new on the db string name

Ok so i have the string "Product". table_name = "Product" I cant do table_name.new undefined method `new So i was trying to find a work around like this table_name = table_name.downcase.pluralize name = ActiveRecord::Base.connection.tables.select { |t| t == table_name }.first name.new I am not sure this will work but even ...

Does MongoDB have a Ruby Shell or Python Shell in addition to the Javascript shell?

Or, does using Ruby's irb and then require 'mongo' and adding some Connect statement essentially act like a Ruby shell... it would be great if a Ruby shell can be possible which as convenient as the Javascript Shell. ...

Which language can change class member dynamically in run time?

I know in Ruby can add and modify method of class dynamically in run time. what about other language? what is C# ,can in this language modify or add some method and ... in run time and dynamically? ...

Stripping the first character of a string

i have string = "$575.00 " string.to_f // => 0.0 string = "575.00 " string.to_f // => 575.0 the value coming in is in this format and i need to insert into a database field that is decimal any suggestions "$575.00 " ...