ruby

seperating key and multiple values for print with .each

I'm probably trying to be hard headed about this. I'm trying to format hash key and and array of values for output to user. Ruby-doc give me the code for it for one value. http://www.ruby-doc.org/core/classes/Hash.html#M002861 h = { "a" => 100, "b" => 200 } h.each {|key, value| puts "#{key} is #{value}" } I'm trying to get h = { "a"...

Can't get rspec, spork and debugger to play nice.

Given I am a dumb programmer and I am using rspec and I am using spork and I want to debug ...mmm...let's saaay, a spec for Phone. Then, where should I put the "require 'ruby-debug'" line in order to halt processing at a particular point in the phone_spec.rb? (All I'm asking for is a big fat arrow that even a challenged programme...

Scanning each HTML node with nokogiri

Hi, How can we scan each element and sub-element of an HTML document with Nokogiri, and testing for each one if the current tag is a block? According to http://wiki.github.com/tenderlove/nokogiri/examples, we can test if an element is a block using: element[:class] == "block" But I don't see how to scan and test each HTML ones... T...

Automatic height of edit box

My shoes application has three items stacked on top of each other (with a stack, of course), in order: A banner An edit box Two buttons in a flow What I want to do is have the banner stay at it's default size (48px) and the buttons as well (I think this may be platform specific?) and have the edit box take up the remaining area on sc...

powerdns-on-rails ArgumentError

My Environments: CentOS 5 ruby 1.8.6 (2008-08-11 patchlevel 287) [x86_64-linux] Ruby Enterprise Edition 20090610 passneger or webrick I use this gem list. *** LOCAL GEMS *** actionmailer (2.3.2, 2.2.2) actionpack (2.3.2, 2.2.2) activerecord (2.3.2, 2.2.2) activeresource (2.3.2, 2.2.2) activesupport (2.3.2, 2.2.2) fastthread (1.0.7) h...

How can I satisfy the warning about no rubyforge_project specified?

When I build a gem, I get (in /home/agrimm/ruby/chaser) WARNING: no rubyforge_project specified Successfully built RubyGem Name: chaser Version: 0.0.2 File: chaser-0.0.2.gem The friendly manual says "Obviously, if your gem doesn’t have a Rubyforge project, leave this setting alone." (I don't have a Rubyforge project) Trying ...

Ruby: extend self

In Ruby, I understand the basic idea of extend. However, what's happening in this segment of code? Specifically, what does extend do? Is it just a convenient way of making the instance methods into class methods? Why would you do it this way rather than specifying class methods from the beginning? module Rake include Test::Unit::Asser...

How do I get colour with Windows command prompt using RSpec in Ruby?

In other o/s RSpec returns nicely coloured results (red, green etc). However in the windows (Vista) command prompt my text output is just plain old boring white. How can I bring colour to my RSpec test results? Thanks Evolve ...

Ruby threads cannot be used in RubyCocoa without patches to the Ruby interpreter

I found this error in Ruby console while I am testing a Rails application. /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib /mongrel.rb:285: in `run': Ruby threads cannot be used in RubyCocoa without patches to the Ruby interpreter So I guess I have to patch or re-install RubyCocoa....

about NSMutabuleArray

ruby code irb(main):001:0> ary = ["a", "b", "b", "a", "b"] irb(main):002:0> ary.uniq! I want to write same code in objective-c. ...

Programmatically take ScreenShot of Desktop in Ruby?

Hey there, I asked this question about taking a picture of a webpage programmatically, and I've downloaded and got webkit2png working (taking pictures of HTML pages like blogs and whatnot). So cool, thanks for showing me that! Now I would like to start doing more, like being able to take pictures of Flash websites after they have load...

Using a Ruby script to login to a website via https

Alright, so here's the dealio: I'm working on a Ruby app that'll take data from a website, and aggregate that data into an XML file. The website I need to take data from does not have any APIs I can make use of, so the only thing I can think of is to login to the website, sequentially load the pages that have the data I need (in this ca...

Iterating through multiple values in a hash and returning a value

I have a hash: hash_example = {777 =>[dog,brown,3], 123=>[cat,orange,2]} I want to go through the hash array value and determine based on the third element which pet is the oldest age. I would choose the max for my method, the part where I figure out which value is associated with max and returning it to the screen is the part I a...

hmac-sha1 in ruby differs from C# HMACSHA1

I am trying to test the API from ankoder.com and have problem on the digest calculation for the authentication token . The sample is ruby while I am trying to call from C#. When I compare the digest result between in HMAC-SHA1, I got issues with the passkey result. To make it easy to test here is the code: require 'hmac-sha1' require ...

RubyOnRails start server runtime error

Hello, I'm trying to run RoR server under ubuntu 9.10: > ruby script/server > => Booting WEBrick > => Rails 2.3.4 application starting on http://0.0.0.0:3000 > /var/lib/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:271:in > `require_frameworks': no such file to > load -- net/https (RuntimeError) > from /var/lib/ge...

Find value in Array

Hi guys, How can I find a value in Array using Ruby 1.8.7 ? ...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para 'Centred paragrpah', :align=>'center' However, this does not work with flows: flow(:align=>'center') do … end No errors are brought up, but the contents remain left justified. ...

Why can't I use attr_accessor inside initialize?

I'm trying to do an instance_eval followed by a attr_accessor inside initialize, and I keep getting this: `initialize': undefined method 'attr_accessor'. Why isn't this working? The code looks kind of like this: class MyClass def initialize(*args) instance_eval "attr_accessor :#{sym}" end end ...

'SSL not supported' when calling https web service in Ruby

I am trying to run the following code to call a webservice from ruby but get an error 'SSL not supported'. I have httpclient 2.1.5.2 installed. require 'soap/wsdlDriver' def validate_certificate(is_ok, ctx) cert = ctx.current_cert unless (cert.subject.to_s == cert.issuer.to_s) #check the server certificate only is_ok &&= File...

What's the Ruby OpenSSL library equivalent of this command?

Hi all, what's the Ruby OpenSSL library equivalent of the following command? openssl pkcs12 -clcerts -nodes -in apns.p12 -out apns.pem I've been reading through the documentation that I could find, but it's so sparsely documented and I'm not having much luck with that. Thanks! ...