[#323752] How do I pass the name of an instance variable into an object? — Glenn <glenn_ritz@...>
Hi,
[#323767] Help using ruby enumerator idioms — Mischa Fierer <f.mischa@...>
Hi,
[#323777] Ruby Command Line One Liner — Alain Helfenstein <a-helfenstein@...>
Hi,
[#323781] rspec file organization — Jon Stenqvist <jon.stenqvist@...>
Hi,
[#323782] Help with HTML parsing — Vivek Netha <vivnet@...>
Hello,
open-uri gives you access to http/https/ftp while Hpricot is a html parser. So for your intended application you would potentially use both - open-uri would fetch the html document and whereas Hpricot would do the parsing using xpath/css selectors etc. open-uri is used when you are loading your html from the web url. The open-uri part happens in the blink of an eye and then you are off manipulating your hpricot doc:
On 2009-01-08, Phlip <phlip2005@gmail.com> wrote:
[#323783] gem cleanup screw up... — "Michael Guterl" <mguterl@...>
I was running `gem cleanup` today, which was long overdue when I
On Thu, Jan 1, 2009 at 8:40 PM, Daniel Berger <djberg96@gmail.com> wrote:
[#323786] Problem with gem, after upgrading to 1.3.1 on linux (ubuntu 8.04) — "Pablo Q." <paqs140482@...>
Ruby doesn't see my installed gems after upgrading to 1.3.1
Pablo Q. wrote:
Sorry, I wrote wrong the mail, test.rb is fine (require 'rubygems')... error
This appears to be the same problem I reported in another thread.
[#323827] Function to flush the variable — Amit Agarwal <amitjhs2000@...>
Hi,
[#323854] Reimplementation address book program — andrea <kerny404@...>
On one of my servers (linux) I have a nice address book over ldap.
[#323881] Default values of hashes — Glenn <glenn_ritz@...>
Hi,
Directly from the rdoc:
I actually have a followup question to this one.=0A=0AIt turns out that som=
[#323905] lost response while transfering large file to FTP server — Clive Lin <lin.zhp@...>
When I used Net::FTP to put large files(about 200MB) to FTP server, the
[#323906] VERY simple question about "?" — Tom Cloyd <tomcloyd@...>
I absolutely love Ruby, but...I've always found the subject of Ruby
Le 4 janvier 2009 12:58, Tom Cloyd a 馗rit :
On Sun, Jan 4, 2009 at 3:34 PM, F. Senault <fred@lacave.net> wrote:
Yaser Sulaiman wrote:
On 04.01.2009 14:48, Tom Cloyd wrote:
On Sun, Jan 4, 2009 at 9:48 AM, Robert Klemme
2009/1/4 Michael Guterl <mguterl@gmail.com>:
Robert Klemme wrote:
On Sun, Jan 4, 2009 at 5:06 PM, Tom Cloyd <tomcloyd@comcast.net> wrote:
On Sun, Jan 4, 2009 at 5:36 PM, Todd Benson <caduceass@gmail.com> wrote:
Todd Benson wrote:
Tom Cloyd wrote:
[#323912] the thread problem in ruby imap — Wen Lan <lanwen.bangba@...>
hi, all
[#323925] Finding filename from a URL — Sam Fent <asbestos999@...>
Hi all,
On 04.01.2009 17:29, Sam Fent wrote:
[#323956] How can I prevent require duplicate files — Zhao Yi <youhaodeyi@...>
In a big ruby project, how to prevent requiring a file multiple times?
Zhao Yi wrote:
Phlip wrote:
Zhao Yi wrote:
Phlip wrote:
There must be a mistake, below is the test I've made. No warning at
LAMBEAU Bernard wrote:
Well, we know that ruby 1.8.x doesn't ensure unique loading with that
[#323960] I can't uninstall a few gems — Oren Golan <orengolan@...>
some info about my system: ubuntu 8.10, ruby 1.8.3, rubygems 1.3.1
[#323966] Question about run external program in Ruby — Zhao Yi <youhaodeyi@...>
I use this method to run a external program in ruby:
On Mon, Jan 5, 2009 at 8:08 AM, Zhao Yi <youhaodeyi@gmail.com> wrote:
[#323972] Coding a server — Vernier -- <aspirine@...>
Hey,
[#323996] noob question: object to string — Darin Ginther <darin.ginther@...>
So I'm able to exercise creating my own class and returning an object
[#324015] Writing accented characters into HTML files? — Kenneth McDonald <kenneth.m.mcdonald@...>
I'm having trouble when I write accented characters into HTML files;
[#324023] improvements to rdoc/alternatives — davetron5000 <davetron5000@...>
I love rdoc, but miss a few things from javadoc, namely the ability to
[#324026] Convert Integers to Strings — Gary Christopher <gary.rafferty@...>
Howdy,
[#324027] WANTED: need a real web API for rubyforge.org — Ryan Davis <ryand-ruby@...>
I just released version 1.0.2 of the rubyforge command line client. It
Trans escreveu:
On Tue, Jan 6, 2009 at 6:08 AM, Tiago Nogueira <tjnogueira@oomaster.com> wrote:
Gregory Brown escreveu:
On Wed, Jan 7, 2009 at 11:07 AM, Tiago Nogueira <tjnogueira@oomaster.com> wrote:
Gregory Brown escreveu:
On Wed, Jan 7, 2009 at 11:38 AM, Tiago Nogueira <tjnogueira@oomaster.com> wrote:
On Wed, Jan 7, 2009 at 10:07 AM, Tiago Nogueira <tjnogueira@oomaster.com> wrote:
On Wed, Jan 7, 2009 at 9:08 AM, Marcelo <marcelo.magallon@gmail.com> wrote:
Would it be worthwhile to consider Redmine (http://www.redmine.org)? It's
Hi,
On Wed, Jan 7, 2009 at 11:12 AM, Daniel Berger <djberg96@gmail.com> wrote:
[#324033] How can I find the source of ruby package installed by gem — Zhao Yi <youhaodeyi@...>
I installed a ruby application by gem. Where can I find its source code?
[#324047] Anyone knows this warning? — Zhao Yi <youhaodeyi@...>
When my ruby runs an external program, it will get this warning:
[#324055] Bug with Ruby/Tk encoding (ruby-1.9.1-rc1) — mdiam <Maurice.Diamantini@...>
Bonjour =E0 tous,
[#324064] Order notes starting at C thru B rather than A thru G — Max Williams <toastkid.williams@...>
Say i have a bunch of note objects, which have a 'name' string, eg 'A'
[#324069] Implementation of Aggregation and Composition — "David B." <dendicus@...>
Hello everybody,
David B. wrote:
[#324079] add 10 minutes to parsed time stamp? — Mmcolli00 Mom <mmc_collins@...>
How can I add 10 minutes to this time stamp? Thanks. MC
On Jan 6, 2009, at 10:09 AM, Mmcolli00 Mom wrote:
Or even better way using ActiveSupport:
On Jan 8, 2009, at 11:54 AM, Jarmo Pertman wrote:
[#324102] Simple Regexp help — Joe Blow <zmanods@...>
How can I test a word to make sure it ONLY contains certain characters?
[#324114] Could not understand this: 3.class is Fixnum or Class — Ruby Rabbit <sentinel.2001@...>
I stored the class of a variable in a variable and later checked in a
[#324125] A question about running external program — Zhao Yi <youhaodeyi@...>
I use this method to run an external program:
[#324127] a good career choice ? — waterinmylungss@...
Hello, I am from the USA and I graduated last year with a BS. I've
[#324147] Puzzling behaviour with range... — Raphael Clancy <raphael.clancy@...>
Hi all!
[#324149] Multiple commands in shell — Gu stav <gustav@...>
I'm trying to run multiple commands in the shell from ruby but I can't
[#324183] tictactoe and choice — andrea <kerny404@...>
I was trying to code the classic tictactoe in ruby.
[#324184] Libraries that need a new home — Daniel Berger <djberg96@...>
Hi,
[#324194] functional programming — "Haris Bogdanovic" <fbogdanovic@...>
Hi.
I know Ruby programming well but I wanted to add funtional paradigm in my
andrea <kerny404@gmail.com> writes:
Pascal J. Bourguignon wrote:
Brian Candler wrote:
Brian Candler <b.candler@pobox.com> writes:
Pascal J. Bourguignon wrote:
Brian Candler wrote:
Mike Gold wrote:
Mike Gold wrote:
Brian Candler wrote:
Brian Candler <b.candler@pobox.com> writes:
[#324201] How to check user name and password for Linux accounts — Zhao Yi <youhaodeyi@...>
Can ruby check user name and password the same way as Linux OS? I use
[#324229] Can you guess what it will be happened? — Jun Young Kim <jykim@...>
Hi. all
It does exactly what I'd expect. The insert line expands to:
[#324253] Does instance_eval passes self as block argument? — "LAMBEAU Bernard" <blambeau@...>
Ruby's documentation of instance_eval shows the "signature" of instance_eval as:
LAMBEAU Bernard schrieb:
obj.instance_eval {| | block } => obj
LAMBEAU Bernard wrote:
Sorry but it does not work:
LAMBEAU Bernard wrote:
[#324262] regular expression question - using 'not' logic with it — Mmcolli00 Mom <mmc_collins@...>
I know this is probably so easy, but I just can't find any documentation
[#324284] calling Ruby from C/C++ — Mr_Tibs <tiberiu.motoc@...>
Hi,
[#324304] code factoring problem — Li Chen <chen_li3@...>
Hi all,
[#324306] Turn off warnings in ruby — Jim Burgess <mr_nice66@...>
Hi,
Jim Burgess wrote:
Hi,
[#324321] about Array methods — Kyung won Cheon <kdream95@...>
l = [1,2,3,4,5]
[#324340] How Ruby — Dhushyanth Ramasamy <r.dushyanth@...>
Well i read the posts on "Why ruby" now I wanted to know "How Ruby":
My view is you start out simple and straightforward. There are no Police
Thanks Mike. I appreciated your post. I'm an awful Ruby programmer, and
Hi --
Hi --
The variable scope rules,
Hi --
[#324355] disable\enable Adobe Flash in the browser — aidy <aidy.lewis@...>
Hi,
[#324379] finding a range of lines from a text document — Adam Akhtar <adamtemporary@...>
Can anyone help me? ill try and keep it short and to the point.
[#324387] Unique identify computer (both Windows and MacOSX) — Fernando Malard <fpmalard@...>
Hello,
[#324395] Using a method as input to another method — Erick Star <phoenix_1177@...>
Hi, I was wondering if it was possible to do something like the
[#324398] Q: most efficient way to remove duplicate spaces in a string? — Mark Watson <mark.watson@...>
I don't usually worry too much about efficiency unless runtime
On Jan 9, 11:20=A0am, Mark Watson <mark.wat...@gmail.com> wrote:
On Fri, Jan 9, 2009 at 11:29 AM, Chris Shea <cmshea@gmail.com> wrote:
On 09.01.2009 19:47, pat eyler wrote:
Robert Klemme wrote:
[#324405] hpricot or nokogiri? — goodieboy <goodieBoy@...>
OK, was completely sold on Hpricot and now am having my doubts. I
[#324410] Behavior of 0 and 0.0... — Raphael Clancy <raphael.clancy@...>
I was playing around with the basic math functions, and I had some
Raphael Clancy <raphael.clancy@gmail.com> wrote:
I've had a little time to think on this (and a little sleep ;-D) and I
On Saturday 10 January 2009 15:23:12 Raphael Clancy wrote:
> eg. in Python:
[#324420] value of an expression? — Kedar Mhaswade <kedar.mhaswade@...>
Sorry if this is asked before and I could not find its answer. Take a
[#324446] Ruby introspection???? — r <rt8396@...>
Hello all,
On Fri, Jan 9, 2009 at 9:49 PM, r <rt8396@gmail.com> wrote:
[#324467] Ruby-based wiki — "Sven S." <svoop@...>
It's a while since the last time this was asked:
[#324508] What is meant by << operator ??? — Muhammad mohsin ali Ma <itismohsinali@...>
What is meant by << operator?
[#324519] Binding.of_caller examples don't work. — Doug <doug14@...>
I'm trying to use the Binding class in the extensions library
[#324520] How to disable the default selection of a radio button? — Li Chen <chen_li3@...>
Hi all,
[#324528] How to build with proper readline version — Mark Fraser <mark6139@...>
Hello,
[#324548] sort hash, hash key and val off by one, see attached — Mmcolli00 Mom <mmc_collins@...>
Please help me with this. I have been trying for days to get this right.
Mmcolli00 Mom wrote:
I figured it make no sense if I tried to explain it in a nutshell. I
[#324550] How can I access after an exception (in the rescue area) the file, class, method, line number for where the error occurred? — "Greg Hauptmann" <greg.hauptmann.ruby@...>
Hi,
When you catch, err, rescue exception look at the 'backtrace' method.
dGhhbmtzIC0gbm8gd2F5IHRvIGdldCB0aGUgY2xhc3MgbmFtZSAmIG1ldGhvZCBuYW1lIHRoZW4/
[#324561] reccommended work flow for unit tests and databases in ruby — Adam Akhtar <adamtemporary@...>
How does one go around creating unit tests for database tables during
Adam Akhtar wrote:
Phlip wrote:
Matt Harrison wrote:
Phlip wrote:
> Well I'm just getting into TDD and thats going well, but I did notice
Phlip wrote:
Matt Harrison wrote:
Phlip wrote:
[#324626] array problem with sorting - maybe easy but not for me — Mmcolli00 Mom <mmc_collins@...>
This code reads in a text file with comma separated values. Problem is,
[#324632] Dynamically created attributes — Peter Marks <petertmarks@...>
I'd like to specify a quantity of object attributes when creating an
On Mon, Jan 12, 2009 at 9:25 AM, Peter Marks <petertmarks@gmail.com> wrote:
[#324654] Data stream variables — Alain Helfenstein <a-helfenstein@...>
Hi
[#324655] Reading RTF + Text File and pattern matching — Sukhwinder Tambar <princetambar@...>
Reading RTF and Text File in Ruby and Pattern Matching/searching from
[#324658] Does ruby support global expression? — Jarod Zhu <zhujie2003info@...>
Hi, all
[#324661] Commonly agreed command line options gem? — LAMBEAU Bernard <blambeau@...>
Hi,
[#324684] XOR two binary strings — Gary Chris <gary.rafferty@...>
Howdy,
[#324692] what's the rules re whether a Hash can use either a Symbol or String to reference the value??? — "Greg Hauptmann" <greg.hauptmann.ruby@...>
Hi,
Greg Hauptmann schrieb:
thanks guys - interesting question for the Rails guys is whether you have to
[#324731] 99.respond_to? :dup ==> true — Ruby Rabbit <sentinel.2001@...>
I have values of various datatypes coming into this method and the
[#324732] How to create a file — Zhao Yi <youhaodeyi@...>
I use this code to write to a file: File.new(@FILE_NAME,"w"). If the
[#324758] rakefile "$0" path in rake — Peter Pk <peterk@...>
Is there a way to get the path to "itself" in a rakefile loaded by rake?
[#324768] getting info about attached displays — Phil Smy <phil@...>
Hi,
[#324769] Various problems after installing ruby 1.9.1 — "Ruby Student" <ruby.student@...>
Team,
[#324772] float: out of range issues — "christoph.heindl@..." <christoph.heindl@...>
Hi,
[#324777] Implementing each and <=> — Ruby Rabbit <sentinel.2001@...>
I have a data model and would like to let it be Enumerable. I want to
[#324781] Grepper 0.9.3: grepping library and commandline tool — "David A. Black" <dblack@...>
Hi --
[#324788] Very rank beginner. — "Ropebender" <ropebender@...>
Help. I am a really new beginner looking at Ruby for the first time.
[#324793] Returning a duplicate from an Array — Jeff Miller <loadeddesigns@...>
Hey guys,
> Hey guys,
> > Hey guys,
This version does only a single pass through the array:
[#324801] Point free (pointless) programming in ruby? — John Carter <john.carter@...>
I'm very fond of the notion of Concatenative Languages such as Joy,
[#324809] Downloading an MP3 from the internet — "Nathaniel Escribano" <americaskate@...>
I am trying to write a simple script that downloads a music file from the
[#324814] Using qui rather than rbuic for qtdesigner .ui files — David Brunell <brunell@...>
I'm trying to load .ui files at runtime using the qui extension and
Alle mercoled=C3=AC 14 gennaio 2009, David Brunell ha scritto:
Stefano Crocco wrote:
Alle gioved=C3=AC 15 gennaio 2009, David Brunell ha scritto:
Stefano Crocco wrote:
Ok, I got it working. Here is my code:
[#324816] Finding ruby.h — "John Ky" <newhoggy@...>
Hi,
[#324830] Higher order ruby — zslevi <zslevi@...>
foo = lambda {|x| lambda {|y| return x+y}}
[#324844] Why do true and false have separate classes — Ruby Rabbit <sentinel.2001@...>
This has puzzled me a bit. I googled and came up with responses like --
[#324861] a beginner case question — Taylor Strait <taylorstrait@...>
I am using case in to determine the sorting method used for an array as
On Wed, Jan 14, 2009 at 4:56 PM, Taylor Strait <taylorstrait@gmail.com> wrote:
[#324870] Ncurses like library? — Tim Mcd <tmcdowell@...>
Excuse me, but does anyone know of an Ncurses-like library for Ruby? For
On Wed, Jan 14, 2009 at 5:31 PM, Tim Mcd <tmcdowell@gmail.com> wrote:
> Hi, this might help:
Andy Cooper wrote:
On Wed, Jan 14, 2009 at 5:49 PM, Tim Mcd <tmcdowell@gmail.com> wrote:
Tim Mcd wrote:
[#324880] Net::SSH serialized commands — lyrics <robin.cyril@...>
Hi,
[#324887] Regexp in Ruby — Teme Rosi <the_beaf@...>
names = ["My name is Jack"]
[#324889] FileUtils.cp_r is slow? — "Paul Lynch" <plynchnlm@...>
I wrote a ruby script to backup files from my hard drive to my flash
[#324898] 10 things to be aware of in 1.8 -> 1.9 transition — "David A. Black" <dblack@...>
Hi --
On Jan 14, 2009, at 12:40 PM, David A. Black wrote:
On Wed, Jan 14, 2009 at 7:40 PM, David A. Black <dblack@rubypal.com> wrote:
> h = { a: 42, b: 42 }
On Thu, Jan 15, 2009 at 3:40 AM, David A. Black <dblack@rubypal.com> wrote:
[#324914] nokogiri 1.1.1 Released — Aaron Patterson <aaron@...>
nokogiri version 1.1.1 has been released!
[#324935] Quizmaster Retiring: Revenge of the Sith — Matthew Moss <matt@...>
Sorry for the dorky subject line...
How about a 'quiz' group with a group leader rather than a single
> Likewise, it may be an easier task to do quizzes only monthly, or =A0
On Thu, Jan 15, 2009 at 5:07 AM, Matthew Moss <matt@moss.name> wrote:
Sorry Matthew if I let some of our private discussions out here but I
update:
> But it is interesting to note that we had quite some discussions and I
On Fri, Jan 16, 2009 at 5:05 PM, Matthew Moss <matt@moss.name> wrote:
Hello Everyone,
Matthew I really appreciated your input. I have however already
On Fri, Jan 16, 2009 at 3:25 PM, Robert Dober <robert.dober@gmail.com> wrote:
On Fri, Jan 16, 2009 at 9:33 PM, Gregory Brown
On Fri, Jan 16, 2009 at 3:50 PM, Robert Dober <robert.dober@gmail.com> wrote:
On Fri, Jan 16, 2009 at 9:57 PM, Gregory Brown
[#324936] ruby json library trouble — Lyes Amazouz <lyesjob@...>
Hi everybody
[#324941] yield example baffling - need help — Tom Cloyd <tomcloyd@...>
I'm studying the yield statement for the first time, today.
[#324950] undefined method `[]' for nil:NilClass - how to prevent? — Mmcolli00 Mom <mmc_collins@...>
This returns correct value so long as I do not use array[0][i]. The
Mmcolli00 Mom wrote:
[#325021] Desktop <-> Web — Trans <transfire@...>
I want to interface a desktop application to a backend web
On Thu, Jan 15, 2009 at 10:39 PM, Trans <transfire@gmail.com> wrote:
On Fri, Jan 16, 2009 at 3:48 PM, Trans <transfire@gmail.com> wrote:
Thomas Sawyer wrote:
P.S. I'm not sure what is the "right" way to serialize Ruby objects in
On Jan 20, 2009, at 4:37 AM, Brian Candler wrote:
James Gray wrote:
That simplifies things a bit. Here it is for completeness:
[#325046] RubyGem, find path of installed gem through ruby. — Aaron Smith <beingthexemplary@...>
Hey All,
Aaron Smith wrote:
Hey Tom, Thanks, that information is definitely what I'm looking for.
or rather, the "INSTALLATION DIRECTORY."
Aaron Smith wrote:
Tom Cloyd wrote:
Tom Cloyd wrote:
there should be something that's part of the rubygem api, so I don't
[#325047] Proc params extension — Tj Holowaychuk <tj@...>
Basically what I need is:
[#325070] Describing degerate dna strings — George George <george.githinji@...>
I am working with strings of 4 letter alphabet a,c,t,g that describe
On Fri, Jan 16, 2009 at 7:54 AM, George George
On Fri, Jan 16, 2009 at 2:56 PM, George George
On Jan 16, 2009, at 9:10 AM, Jes=FAs Gabriel y Gal=E1n wrote:
On Fri, Jan 16, 2009 at 5:51 PM, Rob Biedenharn
[#325110] Son of 10 things! (1.8 to 1.9 transition) — "David A. Black" <dblack@...>
Hi --
David A. Black wrote:
Hi --
[#325114] How to refresh Image through ajax request — Kumar Saurav <saurav@...>
Hi all ,
Kumar Saurav wrote:
[#325117] Monopoly Walker (#188) — Matthew Moss <matt@...>
Okay, this will be the last quiz I host for Ruby Quiz... I hope to
[#325119] Scraping off a Word document? — gregarican <greg.kujawa@...>
Here's a conceptual question. I have a Word mail merge, with a few
[#325126] how to bind to a function with variable number of args — Ollivier Robert <keltia@...>
I'm looking at ruby-ffi 0.2.0 with MRI 1.8.7 (haven't tried with
[#325165] Convert String to Float if and only if the content of the string are digits — Daniel Firu <dannyfiru@...>
Hi All,
[#325202] Time Compare — Cyrus Dev <cyrus_dev@...>
Hello all
Cyrus Dev schrieb:
[#325214] Shoes Video Support on Linux — Trans <transfire@...>
When downloading Shoes for Linux I did not see a binary package with
[#325217] 1.8.6 OCI binary extension question — Tim Hunter <TimHunter@...>
I'm trying to build a new release of RMagick that is compatible with the
[#325218] Re: reading file to list — Xah Lee <xahlee@...>
comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.=
[#325234] If you use PDF::Writer, read this post! — Gregory Brown <gregory.t.brown@...>
I'm getting very few requests for features to add to Prawn that exist
2009/1/18 Gregory Brown <gregory.t.brown@gmail.com>:
On Sat, Jan 17, 2009 at 9:00 PM, Stefan Lang
On Sat, Jan 17, 2009 at 10:12 PM, Trans <transfire@gmail.com> wrote:
Does anybody use this stuff as an alternative to LaTeX?
On Sun, Jan 18, 2009 at 3:32 PM, Redd Vinylene <reddvinylene@gmail.com> wrote:
Too true, too true. LaTeX gives me a headache.
[#325260] What does "@@" mean? — Zhao Yi <youhaodeyi@...>
In a ruby class, what does a variable "@@name" mean? Does it mean static
[#325277] get not working — Free Bird <ratanpd@...>
I have a class Halt. If i type Halt, the output is
[#325282] Thread starvation — Jakub Pavl勛 jn. <severus@...>
Hello,
[#325329] Inochi 0.0.0 — Suraj Kurapati <snk@...>
Inochi 0.0.0
[#325335] how can we call a method without using . operator — ruby rails <bagam_venkat@...>
Hi all,
2009/1/19 ruby rails <bagam_venkat@hotmail.com>
James Coglan wrote:
[#325336] comparing date problem — Sam Ginko <ginkod@...>
I have a set of dates in my database and would like to only get the
Sam Ginko wrote:
Brian Candler wrote:
Sam Ginko wrote:
I'm having a similar issue, but can't seem to figure out what the
[#325348] parsing List results — Fernando Ramos <ramosbrazil@...>
Hi Folks,
[#325353] Converting binary image file to bmp file using RMagick2.0 — Kamaljeet Saini <kamaljeet_singh_saini@...>
We are trying to convert "image1.txt" file which is a binary file to
fyi:
On Monday 19 January 2009 19:09:34 Kamaljeet Saini wrote:
OK, if its 16 bit any way around to get it decoded and proper image out
Kamaljeet Saini wrote:
Hi,
The above posting code worked fine for 704/480 binary to image file but
2009/1/23 Kamaljeet Saini <kamaljeet_singh_saini@hotmail.com>
Hi,
Hi,
The code sent work prefectly fine. Thanks you so much for this help.
2009/1/29 Kamaljeet Saini <kamaljeet_singh_saini@hotmail.com>:
thanks for the reply.
[#325356] migration too slow? — Nic Xie <yudora111@...>
I have a migration including a update_all statement to a big
Maybe sorta OT for this list, but:
[#325388] Gsub!("\n","\n") — Simon Tan <simon1tan@...>
Hi all, I'm not sure why but I assumed gsub! would allow me to replace
On Jan 19, 2009, at 7:19 PM, Simon Tan wrote:
[#325394] 10 numbers in between 2 numbers — jko170 <jko170@...>
How can I get an array of 10 numbers in between two numbers?
[#325414] Zlib Error in ubuntu while installing new gems — Arunkumar Balu <arunkarthick.it@...>
Hi,
[#325417] Is it possible to install exe via ruby code ? — jazzez ravi <jazzezravi@...>
I have a exe file in c:/test.exe
Sorry for the wrong code in previous post
jazzez ravi wrote:
Hi Rodrigo Bermejo,
Hi Rodrigo Bermejo,
jazzez ravi wrote:
David Mullet wrote:
[#325429] Threads After Fork — James Gray <james@...>
Am I understanding this example right:
[#325433] issue using method 'odd?' — Mmcolli00 Mom <mmc_collins@...>
I keep getting a no method error when trying to find out if a count is
[#325446] rails console output shows "\n" rather than putting in new line? is there a way to change this? — "Greg Hauptmann" <greg.hauptmann.ruby@...>
Hi,
[#325453] if statement not working with Hash object — Mmcolli00 Mom <mmc_collins@...>
count1 = Hash.new(0)
Mmcolli00 Mom wrote:
[#325465] ParseTree 3.0.3 Released — Ryan Davis <ryand-ruby@...>
[#325470] flog 2.0.0 Released — Ryan Davis <ryand-ruby@...>
[#325476] wilson 1.0.0 Released — Ryan Davis <ryand-ruby@...>
[#325478] Ruby namespace question — Zhao Yi <youhaodeyi@...>
I require two ruby files which include two classes with the same name.
[#325482] cannot get attr_accessor to work — Tom Cloyd <tomcloyd@...>
I've been staring at this for a couple of hours, and I cannot crack the
Hi --
[#325497] Suggestions and Resources? — Kenny Xm <xarverk@...>
Hi I'm 11 years old and love computers, and want to go into programming.
[#325530] Passwords — John Chant <john.chant@...>
Hi,
[#325535] Class design question — Jes俍 Gabriel y Gal疣 <jgabrielygalan@...>
Hi,
Jes炭s Gabriel y Gal叩n wrote:
On Jan 21, 2009, at 3:26 PM, Ilan Berci wrote:
[#325542] String doesnt auto dup on modification — RK Sentinel <sentinel.2001@...>
I'm writing my first largeish app. One issue that gets me frequently is
2009/1/21 RK Sentinel <sentinel.2001@gmx.com>:
RK Sentinel wrote:
On 21.01.2009 22:57, Brian Candler wrote:
instance variable then I tend to dup it if the application is larger.
RK Sentinel wrote:
Stefan Lang wrote:
2009/1/22 Albert Schlef <albertschlef@gmail.com>:
[#325546] class doesn't know about calling program's libraries? — Tom Cloyd <tomcloyd@...>
I'm still in my first 24 hours of seriously using classes, so am still
Tom Cloyd wrote:
Ilan Berci wrote:
And the exact exception, with backtrace?
[#325547] Showing a file — Sigge Sg <siggesg@...>
I am a noob in programing, and have just learned some of the basics.
[#325559] Help with FasterCSV monkey patch — Alfredo Mesen <albemuth@...>
Hello, I've been trying to monkey patch FCSV to allow escaped colsep
[#325566] Can't read more than one message from a socket — Chris Birkinshaw <chris.birkinshaw@...>
I am connecting to a server and then waiting to receive messages over
[#325602] Separate random number generators? — Bart Braem <bart.braem@...>
For simulation work, I want to use multiple, independent random number
[#325616] Tk supports only GIF? — Albert Schlef <albertschlef@...>
I has this snippet to show images:
From: Albert Schlef <albertschlef@gmail.com>
[#325619] How to use the type in the Mysql::Field object? — Patrick Put <patrick.put@...>
I'm trying to do something like this (not really, I want to use the type
[#325634] Calling class methods from C — Robert Rouse <scyllinice@...>
Hello,
[#325649] Choosing the most appropiate Ruby version and programming model to develop a SIP server — Iñaki Baz Castillo <ibc@...>
Hi, I need to do a choice between the various Ruby versions (1.8, 1.9, JRub=
I単aki Baz Castillo wrote:
2009/1/23 Brian Candler <b.candler@pobox.com>:
I単aki Baz Castillo wrote:
2009/1/23 Brian Candler <b.candler@pobox.com>:
I単aki Baz Castillo wrote:
El Viernes, 23 de Enero de 2009, Brian Candler escribi=C3=B3:
[#325652] How to receive data using socket programming — Kamaljeet Saini <kamaljeet_singh_saini@...>
Hi,
Kamaljeet Saini wrote:
Can someone help please in interpreting the following C# logic/algorithm
I got this following code from
Kamaljeet Saini wrote:
[#325653] simple ruby program problem — Hunter Walker <walkerhunter@...>
So I have been reading Chris Pine's book, "Learn to Program". I am
[#325668] Gathering Ruby Quiz 2 Data (#189) — Daniel Moore <yahivin@...>
Greetings!
On Fri, Jan 23, 2009 at 7:42 AM, Daniel Moore <yahivin@gmail.com> wrote:
What's the deadline btw? I am almost ready with the solution since the
[#325677] running a program without ruby — Sigge Sg <siggesg@...>
I am a noob in programing, so don't be mad if it's a bad question!
[#325721] class 'initialize' method not working ??? — Tom Cloyd <tomcloyd@...>
I'm baffled by this error, after a hour+ of experimentation with
-----BEGIN PGP SIGNED MESSAGE-----
[#325733] regex extension to handle matching parens? — ivo welch <ivowel@...>
Dear Experts: I am very new to ruby, literally having just read the
[#325745] instantiate a class dynamically — "rpardee@..." <rpardee@...>
Hey All,
[#325755] Help on SQLITE3-ruby (1.2.3) Windows problem — jhs408@...
Your Help please:
[#325756] with or without arguments - how? — Jason Lillywhite <jason.lillywhite@...>
I've used methods before that work with or without arguments. I've tried
[#325760] OpenSSL Ruby 1.9? "Certificate verify failed" — Alexandre Alex <alex.vaillancourt@...>
Hi Guys!
[#325768] Creating p7s/pkcs7 files with Ruby — Yves Vogl <yves.vogl@...42.com>
Hi,
[#325777] how to find the position of each match within a string — Li Chen <chen_li3@...>
Hi --
> You can examine the $~ global MatchData object, in a couple of ways:
[#325781] how to require more than one thing from the command line — Roger Pack <rogerpack2005@...>
Is there a way to do this?
Roger Pack wrote:
Roger Pack wrote:
[#325782] gem thought — Roger Pack <rogerpack2005@...>
I noticed how convenient it is to use debgem, I am wondering if it would
Roger Pack schrieb:
[#325797] Scope resolution operator — Daniel Waite <rabbitblue@...>
(The code I will demonstrate is Rails-based, but the question is
[#325812] Question about BlankSlate.reveal — Gregory Brown <gregory.t.brown@...>
Hi folks,
2009/1/25 Gregory Brown <gregory.t.brown@gmail.com>:
[#325813] Listing installed gems — Shilo Ayalon <shiloayalon@...>
Hi -
Alle domenica 25 gennaio 2009, Shilo Ayalon ha scritto:
[#325816] How to pop up a Download Window — Kumar Saurav <saurav@...>
Hi all ,
[#325817] unalias a method? — Todd Burch <promos@...>
I needed to alias a method (alias_method) to change its behavior during
Todd Burch wrote:
Mike Gold wrote:
[#325832] How can I get the arguments passed to the caller. — Stefan Kanev <stefan.kanev@...>
Hey guys.
> I have a rather weird question. I want to write a function that
James Coglan wrote:
Thanks for the advice. I would have never had thought of something as
[#325835] creating facebook — Hellkor Hellkorduo <isitcbh@...>
what about creating facebook with rails !
[#325861] logging 0.9.5 — Tim Pease <tim.pease@...>
logging version 0.9.5
> logging version 0.9.5
[#325870] Need help for Ruby DBI and PostgreSQl — Manisha Tripathy <pujari.manisha@...>
Hi,
Manisha Tripathy wrote:
Brian Candler wrote:
Manisha Tripathy wrote:
Brian Candler wrote:
Manisha Tripathy wrote:
Brian Candler wrote:
[#325871] xml — Harish Dewangan <kd_harish@...>
Hi All,
[#325882] minimal ruby install — Rick Fiorentino <rfiorentino@...>
Hi All,
[#325910] Page crawling and URL grabbing — "Patrick L." <leahy16@...>
Hey guys,
[#325911] Conventions in ruby and the principle of least surprise — Einar Boson <einarmagnus@...>
Hi guys, and hi Matz. I have a few questions about ruby syntax and
Einar Boson wrote:
[#325918] Help on Directory Iteration — Newb Newb <revathy.p@...>
Hi People i have never done file or Directory manipulations before.
[#325921] nokogirl on ubuntu: failed to build gem native extension — Edouard Dantes <edrd.dantes@...>
Hi,
Search and install package named ruby-dev. Notice also that it's
Radosław Bułat wrote:
On May 27, 2009, at 12:52, Alice Gheorghiu wrote:
Eric Hodel wrote:
[#325962] problems with rake and sh — Dave Foo <hunkybill@...>
Hi,
[#325971] Ruby interpreter not working — Will Dresh <w.dresh@...>
Hello,
Alle marted=C3=AC 27 gennaio 2009, Will Dresh ha scritto:
Stefano Crocco wrote:
Rodrigo Bermejo wrote:
On Tue, Jan 27, 2009 at 10:06 PM, Tom Cloyd <tomcloyd@comcast.net> wrote:
On Wed, Jan 28, 2009 at 5:06 AM, Robert Dober <robert.dober@gmail.com>wrote:
> I use gedit with the snippets[1] plugin. I set up a "defi" tap trigger so
[#325974] replacing callcc by catch/throw — Thomas Hafner <thomas@...>
Hello,
[#325983] Super User Can't Change UID? — James Gray <james@...>
Why would the super user not be able to switch UID's?
This works on my gentoo without any problem. Try to became root and
On Jan 27, 2009, at 5:21 PM, Michel Boaventura wrote:
On Jan 27, 2009, at 6:26 PM, James Gray wrote:
[#325987] how can I switch over an array ? — Tsunami Script <lyon2003@...>
I have the following code snippet :
[#326021] regexp multiple matches — Mickael Faivre-Macon <faivrem@...>
Hi,
On Wed, Jan 28, 2009 at 1:26 PM, Mickael Faivre-Macon <faivrem@gmail.com>wrote:
[#326022] how to get an absolute address of a link — Tsunami Script <lyon2003@...>
Is there some URL lib that I can use to get the absolute address of a
[#326027] Defining an ActiveRecord class within a method of another class — Glenn <glenn_ritz@...>
Hi,
[#326036] MiniTest & Test::Unit::TestResult in Ruby 1.9.1 — James Mead <jamesmead44@...>
It looks like Test::Unit::TestResult [1] has disappeared in Ruby 1.9.1. Is
[#326042] function inside a function — Jason Lillywhite <jason.lillywhite@...>
I have a question about the timing of function evaluations in this case:
[#326070] Ruby on Solaris 10 performance problems — Colin Mackenzie <colmac@...>
We just installed ruby on a
2009/1/28 Colin Mackenzie <colmac@gmail.com>:
* Colin Mackenzie <colmac@gmail.com> (2009-01-28) schrieb:
Simon Krahnke wrote:
2009/1/30 Peter Booth <pbooth@nocoincidences.com>:
[#326076] yield vs. return — klochner <klochner@...>
I couldn't find any meaty discussions on this topic, so maybe it's
[#326079] Errno::ENOMEM reading a device in Ruby, not in Java though — Roger Pack <rogerpack2005@...>
Question on how to avoid an Errno::ENOMEM
2009/1/29 Roger Pack <rogerpack2005@gmail.com>:
Hi,
ge of st says:
Hi,
[#326084] Bitwise question — "Andrew Barringer" <abarringer@...>
I'm working on a project that has a bitmap of permissions and I need to
Andrew Barringer <abarringer@bsecure.com> writes:
[#326090] Compiling mysql-ruby-2.8 problems — Alex 2k8 <abc3def@...>
Hello,
[#326096] error with regular expression inside eval block — Barun Singh <barunio@...>
I'm seeing strange behavior with Ruby 1.8 when I try to evaluate a
[#326101] proper use of classes — Tom Cloyd <tomcloyd@...>
Greetings...
2009/1/29 Tom Cloyd <tomcloyd@comcast.net>:
An attractive aspect of Ruby is how it is usually presented as agnostic
On Sat, Jan 31, 2009 at 11:00 PM, Mike Stephens <rubfor@recitel.net> wrote:
Hi --
On 1 Feb 2009, at 11:54, David A. Black wrote:
On Mon, 2 Feb 2009, Eleanor McHugh wrote:
On 2 f=E9vr. 09, at 16:11, Matt Lawrence wrote:
[#326106] RDoc 2.3 now with Darkfish, without CHM and extra HTML templates — Eric Hodel <drbrain@...7.net>
This release of RDoc brings some big changes. Most notably Michael =20
On Thu, Jan 29, 2009 at 6:53 AM, Eric Hodel <drbrain@segment7.net> wrote:
On Jan 29, 2009, at 3:24, Martin DeMello <martindemello@gmail.com>
On Thu, Jan 29, 2009 at 9:14 PM, Eric Hodel <drbrain@segment7.net> wrote:
Eric Hodel wrote:
On Jan 30, 2009, at 5:27 AM, Clifford Heath wrote:
It definitely looks better.
James Gray wrote:
On Jan 30, 2009, at 5:37, James Gray <james@grayproductions.net> wrote:
On Jan 30, 2009, at 03:27 AM, Clifford Heath wrote:
Eric Hodel wrote:
[#326123] Search for string in folder names — Newb Newb <revathy.p@...>
Hi ...
[#326134] Real life use of each_cons? — Mischa Fierer <f.mischa@...>
Hello,
On Thu, Jan 29, 2009 at 12:19 AM, Mischa Fierer <f.mischa@gmail.com> wrote:
[#326165] MiniTest: a curious case of include (1.8 vs 1.9) — Simon Chiang <simon.a.chiang@...>
I've been messing around with minitest and came across something very
As an additional note to this, assigning constants in a describe under
[#326170] Add randomize method to array? — Bart Braem <bart.braem@...>
Perhaps a silly question. What is the best way to add a randomize
[#326175] RDoc plain text docs with command to create an HTML table? — Martin Bernd Schmeil <bschmeil@...24.com>
Hi all,
On Jan 29, 2009, at 08:11 AM, Martin Bernd Schmeil wrote:
[#326183] Ruby 1.9, Ruby Mysql 2.8, Compiling — mwlang88 <mwlang@...>
Hello, all
[#326186] Testing file system manipulations — Chris Vincent <c.j.vincent@...>
I am currently writing a class which processes a log file, inserts some
[#326192] Reading a file in chunks, to a byte array — draygen@...
Hi everyone,
[#326193] Help translating C# socket code equivalent Ruby socket code — Kamaljeet Saini <kamaljeet_singh_saini@...>
Possible to help in translating the following C# socket code to Ruby
[#326196] How to do a for loop...and iterate a set number of times? — Dan No <dan.cao.nguyen@...>
So painfully basic, but I'm just starting Ruby and am coming to it from
[#326216] Can't create a new file — Nebs Petrovic <nebs_man@...>
I have no idea what's going on. I've read about a dozen forums about
[#326226] API to determine traveling distance between two locations? — Aldric Giacomoni <"aldric[removeme]"@...>
Hi all,
[#326241] Object#singleton_class in Ruby 1.9? — Suraj Kurapati <snk@...>
Hello,
Hi --
Hi,
On Fri, Jan 30, 2009 at 10:28 AM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
On Jan 30, 2009, at 9:47 AM, Gregory Brown wrote:
Yukihiro Matsumoto wrote:
Thomas Sawyer wrote:
On Fri, Jan 30, 2009 at 3:28 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
On Fri, Jan 30, 2009 at 4:28 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
Robert Dober wrote:
On Sat, Jan 31, 2009 at 8:03 PM, Thomas Sawyer <transfire@gmail.com> wrote:
Hi --
On Sun, Feb 1, 2009 at 12:03 PM, David A. Black <dblack@rubypal.com> wrote:
David A. Black wrote:
Hi --
David A. Black wrote:
Hi --
David A. Black wrote:
On Tue, 3 Feb 2009, Thomas Sawyer wrote:
[#326247] MySQL gem maintainer and project page? — Luis Lavena <luislavena@...>
Hello Everybody,
[#326276] Ruby 1.9.1 is released — "Yugui (Yuki Sonoda)" <yugui@...>
-----BEGIN PGP SIGNED MESSAGE-----
On Jan 30, 2009, at 10:38 AM, Yugui (Yuki Sonoda) wrote:
Yugui (Yuki Sonoda) wrote:
Congradulations guys!! I am a noob so this might be a silly question to the
On Fri, Jan 30, 2009 at 10:08 PM, Yugui (Yuki Sonoda) <yugui@yugui.jp> wrote:
Are there going to be a one click installer for this new version? I'm having
Zayd Abdullah wrote:
On Jan 31, 8:34=A0am, Jayce Meade <azimuth-rubyt...@live.com> wrote:
[#326280] Hexagonal Grid Game Board (#190) — Daniel Moore <yahivin@...>
Summary of quiz #189 coming in a day or two.
[#326349] File::write() complement for File::read() ? — Suraj Kurapati <snk@...>
Hello,
[#326350] difference in file.join between Linux, win32? — Roger Pack <rogerpack2005@...>
question:
[#326361] global generator of unique symbols — Thomas Hafner <thomas@...>
Hello,
Thomas Hafner <thomas@faun.hafner.nl.eu.org> writes:
[#326392] rake db:migrate not working — Chris Gunnels <rfsllc@...>
I keep getting access denied for user 'root'@'localhost' (using
[#326402] ruby string question — Tsunami Scripter <lyon2003@...>
Is it possible to modify an existing ruby string without creating a new
[#326412] Array#to_h — Roger Pack <rogerpack2005@...>
Not that I would find it useful at all, but is there is a Hash#to_a
Hi --
It's fairly trivial, isn't it?
[SUMMARY] Monopoly Walker (#188)
Writing a simulator for a complete Monopoly game isn't overly complex,
but it does require a lot of attention to detail in order to
accurately reflect the game rules. Writing a simulator for just the
movement portion of the game should be much simpler -- you can ignore
property purchases and auctions, money tracking, rent, hotels, etc.
What makes such a simulator non-trivial is the possibility of jumping
around. If the only way to move around the board was via a dice rolls,
the expected pattern to landing on properties would be even; that is,
no one property would be more valuable than any other. However, when
the Community Chest and Chance cards are added in, along with the
Jail, the distribution is no longer even. When running the submission
from _Daniel Moore_ for 10,000,000 iterations, the top ten properties
show up as:
Jail/Just Visiting - 5.0660%
GO - 4.4057%
Reading Railroad - 3.7458%
Mediterranean - 3.4747%
Income Tax - 3.3711%
Baltic - 3.3506%
Community Chest - 3.2478%
Oriental - 2.8945%
Illinois - 2.6351%
New York - 2.5123%
Now, four of those properties cannot be owned. The other six amount to
almost 20% of property landings. And, interestingly, two of the
highest properties are Mediterranean and Baltic, which form a monopoly.
I'll note here that I believe Daniel's simulation to be a good start,
but has some problems. I found one bug. It does not simulate the
rolling of doubles to escape Jail, which would have an impact on the
twelve properties that follow. Also, I'm not certain the handling of
Community Chest and Chance cards is mathematically accurate, but may
be reasonably close. Additionally, the human factor is completely
removed here, which may be significant.
In any case, while you may want to improve the script before preparing
for your next game of Monopoly, we can certainly look at what Daniel
has done. Let's begin with the overall simulation:
class Board
# ...
def simulate(moves)
@moves = moves
position = 0
@moves.times do
position += roll
# Land on the properties and keep following the cards until we
stay put
while( position != (new_position = (@properties[position %
BOARD_SIZE]).land) ) do
position = new_position
# Track the extra moves
@moves += 1
end
end
end
# ...
end
board = Board.new
board.simulate((ARGV[0] || 100000).to_i)
One parameter is pulled from the command line to be the number of
simulation steps (i.e. dice rolls) to make, defaulting to 100,000 is
no argument is provided. The board is created and `simulate` called.
Inside, we loop, calculating the next position, finding the
corresponding property, and calling `land` on that property. `land`
will return new position, often itself, unless some condition causes
the player to move elsewhere. If that happens (and so `position` will
not equal `new_position`), we update `position` and increase `@moves`,
just to keep track of how many moves were made overall (compared to
how many rolls, the original parameter). When we look at `land`, we'll
see the bookkeeping for tracking landing counts.
There is a bug here, however: the calculation of `position`. In most
cases, when you don't move beyond the roll, `land` will return the
index into `@properties`: that is, `position % BOARD_SIZE`. Usually,
this will be the same as `position`, except when passing Go (e.g. 46 !
= 6). In such a case, the move count will be incremented
inappropriately, and `land` will be called once too often. To fix,
change the loop to:
@moves.times do
position += roll
position %= BOARD_SIZE
# Land on the properties and keep following the cards until we
stay put
while( position != (new_position = (@properties[position]).land) )
do
position = new_position
# Track the extra moves
@moves += 1
end
end
A seemingly minor bug, but this is why Baltic, Mediterranean, and
Oriental showed up near the top of the distribution; they are the
properties that would be hit more frequently when moving past Go. When
this bug is fixed, the top ten distribution of properties is:
Jail/Just Visiting - 5.4544%
Illinois - 2.9668%
GO - 2.9018%
New York - 2.8461%
B&O Railroad - 2.8458%
Reading Railroad - 2.7957%
Community Chest - 2.7122%
Pennsylvania Railroad - 2.7024%
Tennessee - 2.6937%
Free Parking - 2.6587%
Now we see Illinois Avenue, B&O Railroad and GO are closer to the top,
which are the three most landed on properties according to most
sources I've seen, including the Monopoly wiki. (Not sure why Jail is
so high... and New York would drop in rank once in-Jail rolls are
handled correctly).
Let's now look a bit at the `Property` class, that which tracks how
often a player lands on the property.
class Property
@@property_count = 0
attr_accessor :count
def initialize(name, block)
@count = 0
@name = name.gsub('_', ' ')
@position = @@property_count
@@property_count += 1
@move_block = block
end
# Record that the token landed on this cell
# Return any bonus move (new location)
def land
@count += 1
# Sometimes cells have a bonus move, this returns
# the new location, could be the same if no bonus move.
@move_block.call(@position)
end
#...
end
The basics of this class is pretty simple: a `@count` data member is
initialized to zero at creation, and incremented once for each call to
`land`. `attr_accessor` provides a way to get the count later. `@name`
is also initialized at creation.
`@move_block` is also assigned at creation; this is a code block that,
given a position, will return another position. The idea here is that
some spots on the board (such as Chance, Community Chest, and Go to
Jail) will immediately move the player somewhere else. Calling this
block (provided elsewhere) will return the new position. In most
cases, where the player does not move, the `stay_put` block is used;
given the current position, it returns that same position -- the
player will stay in one place.
stay_put = Proc.new {|cur_pos| cur_pos}
My main concern with the `Property` class is the duplication of effort
found in `@@property_count`. The idea is to have each newly created
property receive a unique index, stored in `@position`. However, this
information is already provided externally by the `PROPERTY_NAMES`
constant array, which dictates the order in which properties are
created. Whenever you have two data "masters", you run the risk that
they disagree. My revision would be to lose `@@property_count` and
pass an extra parameter into the initializer.
class Property
#...
def initialize(pos, name, block)
@count = 0
@position = pos
@name = name.gsub('_', ' ')
@move_block = block
end
#...
end
Also, I would like to change `attr_accessor` to `attr_reader`, but the
`count` field is written to later in the code. However, it is reused
for a purpose other than the count; it would be better to provide a
separate data member, appropriately named, rather than overlap use of
`count`. Or, better yet, calculate the frequency on the fly, since
it's a simple calculation that doesn't need to be stored.
The last thing I'll look at here is one of the code blocks used to
handle special movement around the board. There are a few of them, but
let's look at the block for handling Chance cards. (The other blocks
are reasonably similar.)
CHANCE_EFFECT = Proc.new do |cur_pos|
case Kernel.rand(CHANCE_CARDS)
when 0
GO_POSITION
when 1
ILLINOIS_POSITION
when 2
# Nearest Utility
if (cur_pos >= WATER_WORKS_POSITION) || (cur_pos <
ELECTRIC_COMPANY_POSITION)
ELECTRIC_COMPANY_POSITION
else
WATER_WORKS_POSITION
end
when 3..4
# Nearest Railroad
case cur_pos
when 5..14
15
when 15..24
25
when 25..34
35
else
READING_POSITION
end
when 5
ST_CHARLES_POSITION
when 6
# Go back three spaces
cur_pos - 3
when 7
JAIL_POSITION
when 8
READING_POSITION
when 9
BOARDWALK_POSITION
else
# This card does not have an effect on position
cur_pos
end
end
Each time the block is called, a "card" is chosen at rand, and the
player's new position is returned. In many cases (i.e. the `else`
statement), the current position is returned; that is, there is no
addition movement beyond the where the player is located.
In most other cases, constants (e.g. ILLINOIS_POSITION) are used to
provide the new location. The `case` statement is a decent,
straightforward mechanism for sorting this out. (I can imagine other
ways to do this, but I leave those as an exercise for the reader. Ha.)
What I will mention here are how those constants are initialized, and
also the use of some hardcoded numbers. For the latter, the approach
that worked for the "nearest utility" case would be suitable for the
railroads. (Personally, I'd probably turn it into a mathematical
formula.) But even assuming we turn the hardcoded numbers into
constants, how are those defined?
GO_POSITION = 0
ILLINOIS_POSITION = 24
BOARDWALK_POSITION = 39
Now, normally, this would be the place to put the literal integers;
however, as mentioned before, this is another "master" in generating
board position numbers. All this information is present in the array
`PROPERTY_NAMES`. To make use of that master array, rather than
providing redundant information, I would do this:
GO_POSITION = PROPERTY_NAMES.index("GO")
ILLINOIS_POSITION = PROPERTY_NAMES.index("Illinois")
BOARDWALK_POSITION = PROPERTY_NAMES.index("Boardwalk")
Likewise,
BOARD_SIZE = PROPERTY_NAMES.size
instead of:
BOARD_SIZE = 40
Note, while the property names are being repeated here, it is (in a
way) not redundant information, since it is not acting as an authority
for property names (as the literal integers were). Also note, with the
flexibility of Ruby, this could be made even less redundant and more
compact, but that's not something I'm going to get into here.
Thanks for the submission, Daniel! It was good fun to see your approach.
And thanks for everyone during my stint as quizmaster. I look forward
to seeing more great quizzes in the future from quizmaster, version
3.0! :D