Chad Perrin | 1 Nov 2008 01:00
Gravatar

Re: Small, simple Ruby applications and sample code?

On Sat, Nov 01, 2008 at 07:15:34AM +0900, Double Minus wrote:
> Chad Perrin wrote:
> > On Sun, Oct 05, 2008 at 09:59:40AM +0900, Double Minus wrote:
> >> 
> >> I have no idea how to use/install/play the game.  I downloaded the zip, 
> >> read the readme...now what?  Thanks everyone!  The 99 bottles tutorial 
> >> was extremely helpful.
> > 
> > Somehow, I managed to miss this when it first appeard on the list about
> > thre weeks ago.  Sorry about that.
> > 
> > I'm glad the 99 bottles thing helped.  How are things progressing now?
> 
> I never really did figure out how to use the game.  (I completed the 
> first level then didn't know what to do from there).
> 
> Things have progressed well.  The Shoes GUI has been amazing to use and 
> learn from.  I am grateful for it.  However I'm seeking a position at my 
> company where Ruby is not useful, so I've been focusing my studies on 
> other topics (CSS, Javascript).  Thanks for checking in.  Great 
> community.

Sometimes it's best to just pick a language and stick with it for a
while, and if you're doing a lot of work with JavaScript in "the real
world" anyway, maybe that's what you should focus on.  Ruby will still be
here when you find the time again to give it the attention it deserves,
and so will the community I'm sure.

I really do think it's a good idea to come back to Ruby at some point,
though.  It's a great language, and I at least find it a lot more fun to
(Continue reading)

Christian | 1 Nov 2008 01:09

n-dimensional array in Ruby

Hi,

i have a little Java problem, I want to solve using Ruby. Therefor I
need an n-dimensional array. In Java it looks like this:

double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()
+y.length()+3];
dArray[0][0][0] = 0;
dArray[0][0][1] = POSITIVE_INFINITY;

Further values will be computed through loops and written into the
array.

How do I initialize such an array in Ruby?

Michael Guterl | 1 Nov 2008 01:29
Picon
Gravatar

Re: n-dimensional array in Ruby

On Fri, Oct 31, 2008 at 8:09 PM, Christian <stadeschuldt <at> googlemail.com> wrote:
> Hi,
>
> i have a little Java problem, I want to solve using Ruby. Therefor I
> need an n-dimensional array. In Java it looks like this:
>
> double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()
> +y.length()+3];
> dArray[0][0][0] = 0;
> dArray[0][0][1] = POSITIVE_INFINITY;
>
> Further values will be computed through loops and written into the
> array.
>
> How do I initialize such an array in Ruby?
>
Infinity = 1.0/0

a = [[],[],[]]
a[0][0][0] = 0
a[0][0][1] = Infinity

The arrays will grow to whatever size you need them to.

HTH,
Michael Guterl

Mike Gold | 1 Nov 2008 01:45
Picon

Re: n-dimensional array in Ruby

Christian wrote:
> i have a little Java problem, I want to solve using Ruby. Therefor I
> need an n-dimensional array.

def Array.multi(*dimensions)
  dimensions.reverse.inject(nil) { |result, dim|
    Array.new(dim) { result ? result.dup : nil }
  }
end

a = Array.multi(3, 4, 5)

p a[0]     #=> [[nil, nil, ...], ... ]
p a[0][0]  #=> [nil, nil, nil, nil, nil]

a[0][0][0] = :fred
a[2][3][4] = :barney

p a[0][0][0]  #=> :fred
p a[2][3][4]  #=> :barney

a[3][0][0]
# => exception: undefined method `[]' for nil; index past dim size
--

-- 
Posted via http://www.ruby-forum.com/.

Thomas Hurst | 1 Nov 2008 02:38

Re: [ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9

* Charles Oliver Nutter (charles.nutter <at> sun.com) wrote:

> The JRuby team is proud to announce the release of FFI for Ruby
> 1.8.6/7 and 1.9!

> Finally, there's no need to write a C extension to call C libraries,
> and the same FFI code will work in Ruby 1.8.6/7, Ruby 1.9, JRuby
> 1.1.4+, and Rubinius (though Rubinius has no callback support yet).

Awesome.  I've used DL to link up some custom libs to a Ruby service,
will give FFI a go and see how it compares :)

Are things like structs likely to be supported in future, ala Python
ctypes?

--

-- 
Thomas 'Freaky' Hurst
    http://hur.st/

Zhang Zhai | 1 Nov 2008 02:53
Favicon

Re: Problem with Mechanize

你好,呵呵,想练练手咯。其他站点都可以,就这个不行,郁闷。

李光 wrote:
> Zhang Zhai 写道:
>>      <at> verbose = verbose
>>     login_form.password =  <at> auth['password']
>> kx.login
>> `bases': undefined method `search' for nil:NilClass (NoMethodError)
>> c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.3/lib/www/mechanize.rb:433:in
>>         from
>> Can anyone help?thanks!
>>   
> 晕,你也遇到这个问题了。我的问题和你一样。呵呵。准备对开心网下手~?

--

-- 
Posted via http://www.ruby-forum.com/.

Charles Oliver Nutter | 1 Nov 2008 06:40
Picon
Gravatar

Re: [ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and 1.9

Thomas Hurst wrote:
> * Charles Oliver Nutter (charles.nutter <at> sun.com) wrote:
> 
>> The JRuby team is proud to announce the release of FFI for Ruby
>> 1.8.6/7 and 1.9!
> 
>> Finally, there's no need to write a C extension to call C libraries,
>> and the same FFI code will work in Ruby 1.8.6/7, Ruby 1.9, JRuby
>> 1.1.4+, and Rubinius (though Rubinius has no callback support yet).
> 
> Awesome.  I've used DL to link up some custom libs to a Ruby service,
> will give FFI a go and see how it compares :)
> 
> Are things like structs likely to be supported in future, ala Python
> ctypes?

Actually structs are already supported! See the blog post, and I believe 
there's some examples shipped with the gem. There needs to be more docs, 
certainly, and hopefully they'll get some TLC soon.

Also, I forgot to call out Evan Phoenix for coming up with the API and 
initial design, and he or someone else on Rubinus wrote up the 
templating/header-file-processing stuff as well. And of course a huge 
thanks to Wayne Meissner for implementing FFI not just once (for JRuby) 
but twice (for C Ruby). His work will mean a huge leap forward in 
cross-impl portability.

- Charlie

(Continue reading)

ara.t.howard | 1 Nov 2008 06:40
Picon
Gravatar

Re: How to access to local variables in enclosing scopes?


On Oct 31, 2008, at 3:08 PM, Yuh-Ruey Chen wrote:

> But something like:
>
> x = 10
> def foo
> 	scope.x
> end
>
> would not be as fragile, assuming |scope| is a new builtin method that
> does what you'd expect it do.

you can write it yourself now

cfp:~ > cat a.rb
class C
   include(
      Module.new do
        y = 42
        def x() y end

       define_method :method_missing do |_|
         if((_ = local_variables.index(_.to_s)))
           eval local_variables[_]
         else
           super
         end
       end
     end
(Continue reading)

Symonds Symonds | 1 Nov 2008 07:04
Picon

hi i am new

Hi am new comer to this site. I am very happy to join this forum. I
gathered lot of information from this site. I enjoyed when i read those
posts in this forum.

<a href="http://www.fastrealestate.com.au">Real Estate</a>
--

-- 
Posted via http://www.ruby-forum.com/.

Jason Leong | 1 Nov 2008 07:11

Indexed arrays, delete_if, and performance

Dear all,

My application uses a calendar which I'm populating using an array of
indexed RollingEvent objects. A RollingEvent is one of a series,
multiplied from its original Event's repeat options (daily, weekly,
fortnightly etc). The idea is that when a user saves an Event, the app
uses a loop to generate and store all the RollingEvents for the coming
year.

So a new Event is added, add_rolling_event is called within the loop
(I've omitted most of the params for readability):

 def add_rolling_event(id, title, calendar_date)
     <at> events[calendar_date.to_date] ||= []
     <at> events[calendar_date.to_date] << RollingEvent.new(id, title,
calendar_date)
 end

The indexing works well, as in the calendar view I can quickly pull out
the RollingEvent objects for that specific day. For the moment, whenever
an Event is edited the entire  <at> events array is reset and a routine loops
through all Events to re-generate RollingEvents.

I'm trying to speed up the process by just deleting the RollingEvents
pertinent to the Event that's being edited, then calling
add_rolling_event for the Event in question.

I have 3 questions:

1. Is using an indexed array actually faster than picking out events on
(Continue reading)


Gmane