[#323782] Help with HTML parsing — Vivek Netha <vivnet@...>

Hello,

13 messages 2009/01/01

[#323881] Default values of hashes — Glenn <glenn_ritz@...>

Hi,

16 messages 2009/01/03

[#323906] VERY simple question about "?" — Tom Cloyd <tomcloyd@...>

I absolutely love Ruby, but...I've always found the subject of Ruby

25 messages 2009/01/04
[#323908] Re: VERY simple question about "?" — "F. Senault" <fred@...> 2009/01/04

Le 4 janvier 2009 12:58, Tom Cloyd a 馗rit :

[#323910] Re: VERY simple question about "?" — "Yaser Sulaiman" <yaserbuntu@...> 2009/01/04

On Sun, Jan 4, 2009 at 3:34 PM, F. Senault <fred@lacave.net> wrote:

[#323913] Re: VERY simple question about "?" — Tom Cloyd <tomcloyd@...> 2009/01/04

Yaser Sulaiman wrote:

[#323920] Re: VERY simple question about "?" — Robert Klemme <shortcutter@...> 2009/01/04

On 04.01.2009 14:48, Tom Cloyd wrote:

[#323923] Re: VERY simple question about "?" — "Michael Guterl" <mguterl@...> 2009/01/04

On Sun, Jan 4, 2009 at 9:48 AM, Robert Klemme

[#323924] Re: VERY simple question about "?" — "Robert Klemme" <shortcutter@...> 2009/01/04

2009/1/4 Michael Guterl <mguterl@gmail.com>:

[#323944] Re: VERY simple question about "?" — Tom Cloyd <tomcloyd@...> 2009/01/04

Robert Klemme 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?

12 messages 2009/01/05

[#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

38 messages 2009/01/05
[#324040] Re: WANTED: need a real web API for rubyforge.org — Trans <transfire@...> 2009/01/06

[#324065] Re: WANTED: need a real web API for rubyforge.org — Tiago Nogueira <tjnogueira@...> 2009/01/06

Trans escreveu:

[#324145] Re: WANTED: need a real web API for rubyforge.org — "Gregory Brown" <gregory.t.brown@...> 2009/01/07

On Tue, Jan 6, 2009 at 6:08 AM, Tiago Nogueira <tjnogueira@oomaster.com> wrote:

[#324146] Re: WANTED: need a real web API for rubyforge.org — Tiago Nogueira <tjnogueira@...> 2009/01/07

Gregory Brown escreveu:

[#324152] Re: WANTED: need a real web API for rubyforge.org — "Gregory Brown" <gregory.t.brown@...> 2009/01/07

On Wed, Jan 7, 2009 at 11:07 AM, Tiago Nogueira <tjnogueira@oomaster.com> wrote:

[#324155] Re: WANTED: need a real web API for rubyforge.org — Tiago Nogueira <tjnogueira@...> 2009/01/07

Gregory Brown escreveu:

[#324163] Re: WANTED: need a real web API for rubyforge.org — "Gregory Brown" <gregory.t.brown@...> 2009/01/07

On Wed, Jan 7, 2009 at 11:38 AM, Tiago Nogueira <tjnogueira@oomaster.com> wrote:

[#324159] Re: WANTED: need a real web API for rubyforge.org — Marcelo <marcelo.magallon@...> 2009/01/07

On Wed, Jan 7, 2009 at 10:07 AM, Tiago Nogueira <tjnogueira@oomaster.com> wrote:

[#324127] a good career choice ? — waterinmylungss@...

Hello, I am from the USA and I graduated last year with a BS. I've

23 messages 2009/01/07

[#324194] functional programming — "Haris Bogdanovic" <fbogdanovic@...>

Hi.

87 messages 2009/01/08
[#324498] Re: functional programming — pjb@... (Pascal J. Bourguignon) 2009/01/10

Brian Candler <b.candler@pobox.com> writes:

[#324502] Re: functional programming — Brian Candler <b.candler@...> 2009/01/10

Pascal J. Bourguignon wrote:

[#324340] How Ruby — Dhushyanth Ramasamy <r.dushyanth@...>

Well i read the posts on "Why ruby" now I wanted to know "How Ruby":

22 messages 2009/01/09
[#324341] Re: How Ruby — Mike Stephens <rubfor@...> 2009/01/09

My view is you start out simple and straightforward. There are no Police

[#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

14 messages 2009/01/09

[#324410] Behavior of 0 and 0.0... — Raphael Clancy <raphael.clancy@...>

I was playing around with the basic math functions, and I had some

16 messages 2009/01/09

[#324420] value of an expression? — Kedar Mhaswade <kedar.mhaswade@...>

Sorry if this is asked before and I could not find its answer. Take a

20 messages 2009/01/09

[#324519] Binding.of_caller examples don't work. — Doug <doug14@...>

I'm trying to use the Binding class in the extensions library

17 messages 2009/01/10

[#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

15 messages 2009/01/11

[#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,

9 messages 2009/01/12

[#324793] Returning a duplicate from an Array — Jeff Miller <loadeddesigns@...>

Hey guys,

12 messages 2009/01/13

[#324830] Higher order ruby — zslevi <zslevi@...>

foo = lambda {|x| lambda {|y| return x+y}}

13 messages 2009/01/14

[#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 --

18 messages 2009/01/14

[#324870] Ncurses like library? — Tim Mcd <tmcdowell@...>

Excuse me, but does anyone know of an Ncurses-like library for Ruby? For

20 messages 2009/01/14

[#324898] 10 things to be aware of in 1.8 -> 1.9 transition — "David A. Black" <dblack@...>

Hi --

23 messages 2009/01/14

[#324935] Quizmaster Retiring: Revenge of the Sith — Matthew Moss <matt@...>

Sorry for the dorky subject line...

38 messages 2009/01/14
[#325027] Re: Quizmaster Retiring: Revenge of the Sith — "Martin DeMello" <martindemello@...> 2009/01/15

On Thu, Jan 15, 2009 at 5:07 AM, Matthew Moss <matt@moss.name> wrote:

[#325055] Re: Quizmaster Retiring: Revenge of the Sith — "Robert Dober" <robert.dober@...> 2009/01/16

Sorry Matthew if I let some of our private discussions out here but I

[#325121] Re: Quizmaster Retiring: Revenge of the Sith — Matthew Moss <matt@...> 2009/01/16

> But it is interesting to note that we had quite some discussions and I

[#325123] Re: Quizmaster Retiring: Revenge of the Sith — "Robert Dober" <robert.dober@...> 2009/01/16

On Fri, Jan 16, 2009 at 5:05 PM, Matthew Moss <matt@moss.name> wrote:

[#325144] Re: Quizmaster Retiring: Revenge of the Sith — "Daniel Moore" <yahivin@...> 2009/01/16

Hello Everyone,

[#325149] Re: Quizmaster Retiring: Revenge of the Sith — Matthew Moss <matt@...> 2009/01/16

[#325021] Desktop <-> Web — Trans <transfire@...>

I want to interface a desktop application to a backend web

19 messages 2009/01/15
[#325066] Re: Desktop <-> Web — Martin DeMello <martindemello@...> 2009/01/16

On Thu, Jan 15, 2009 at 10:39 PM, Trans <transfire@gmail.com> wrote:

[#325046] RubyGem, find path of installed gem through ruby. — Aaron Smith <beingthexemplary@...>

Hey All,

11 messages 2009/01/16

[#325070] Describing degerate dna strings — George George <george.githinji@...>

I am working with strings of 4 letter alphabet a,c,t,g that describe

12 messages 2009/01/16

[#325114] How to refresh Image through ajax request — Kumar Saurav <saurav@...>

Hi all ,

13 messages 2009/01/16

[#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

10 messages 2009/01/17

[#325218] Re: reading file to list — Xah Lee <xahlee@...>

comp.lang.lisp,comp.lang.scheme,comp.lang.functional,comp.lang.python,comp.=

18 messages 2009/01/17

[#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

19 messages 2009/01/18
[#325235] Re: If you use PDF::Writer, read this post! — Stefan Lang <perfectly.normal.hacker@...> 2009/01/18

2009/1/18 Gregory Brown <gregory.t.brown@gmail.com>:

[#325236] Re: If you use PDF::Writer, read this post! — Gregory Brown <gregory.t.brown@...> 2009/01/18

On Sat, Jan 17, 2009 at 9:00 PM, Stefan Lang

[#325242] Re: If you use PDF::Writer, read this post! — Trans <transfire@...> 2009/01/18

[#325243] Re: If you use PDF::Writer, read this post! — Gregory Brown <gregory.t.brown@...> 2009/01/18

On Sat, Jan 17, 2009 at 10:12 PM, Trans <transfire@gmail.com> wrote:

[#325254] Re: If you use PDF::Writer, read this post! — "Redd Vinylene" <reddvinylene@...> 2009/01/18

Does anybody use this stuff as an alternative to LaTeX?

[#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

18 messages 2009/01/19
[#325495] Re: Converting binary image file to bmp file using RMagick2.0 — Heesob Park <phasis@...> 2009/01/21

Hi,

[#325629] Re: Converting binary image file to bmp file using RMagick2.0 — Kamaljeet Saini <kamaljeet_singh_saini@...> 2009/01/22

The above posting code worked fine for 704/480 binary to image file but

[#325417] Is it possible to install exe via ruby code ? — jazzez ravi <jazzezravi@...>

I have a exe file in c:/test.exe

13 messages 2009/01/20
[#325418] Re: Is it possible to install exe via ruby code ? — jazzez ravi <jazzezravi@...> 2009/01/20

Sorry for the wrong code in previous post

[#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

34 messages 2009/01/21

[#325602] Separate random number generators? — Bart Braem <bart.braem@...>

For simulation work, I want to use multiple, independent random number

19 messages 2009/01/22

[#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=

11 messages 2009/01/22
[#325675] Re: Choosing the most appropiate Ruby version and programming model to develop a SIP server — Brian Candler <b.candler@...> 2009/01/23

I単aki Baz Castillo wrote:

[#325683] Re: Choosing the most appropiate Ruby version and programming model to develop a SIP server — Iñaki Baz Castillo <ibc@...> 2009/01/23

2009/1/23 Brian Candler <b.candler@pobox.com>:

[#325652] How to receive data using socket programming — Kamaljeet Saini <kamaljeet_singh_saini@...>

Hi,

11 messages 2009/01/22

[#325668] Gathering Ruby Quiz 2 Data (#189) — Daniel Moore <yahivin@...>

Greetings!

12 messages 2009/01/23

[#325870] Need help for Ruby DBI and PostgreSQl — Manisha Tripathy <pujari.manisha@...>

Hi,

14 messages 2009/01/26

[#325921] nokogirl on ubuntu: failed to build gem native extension — Edouard Dantes <edrd.dantes@...>

Hi,

13 messages 2009/01/27

[#325971] Ruby interpreter not working — Will Dresh <w.dresh@...>

Hello,

14 messages 2009/01/27
[#325972] Re: Ruby interpreter not working — Stefano Crocco <stefano.crocco@...> 2009/01/27

Alle marted=C3=AC 27 gennaio 2009, Will Dresh ha scritto:

[#325973] Re: [initialize keyword] Ruby interpreter not working — Rodrigo Bermejo <rodrigo.bermejo@...> 2009/01/27

Stefano Crocco wrote:

[#325974] replacing callcc by catch/throw — Thomas Hafner <thomas@...>

Hello,

16 messages 2009/01/27

[#325983] Super User Can't Change UID? — James Gray <james@...>

Why would the super user not be able to switch UID's?

14 messages 2009/01/27

[#326070] Ruby on Solaris 10 performance problems — Colin Mackenzie <colmac@...>

We just installed ruby on a

18 messages 2009/01/28

[#326084] Bitwise question — "Andrew Barringer" <abarringer@...>

I'm working on a project that has a bitmap of permissions and I need to

14 messages 2009/01/28

[#326101] proper use of classes — Tom Cloyd <tomcloyd@...>

Greetings...

32 messages 2009/01/29
[#326439] Its a Free Language — Mike Stephens <rubfor@...> 2009/01/31

An attractive aspect of Ruby is how it is usually presented as agnostic

[#326461] Re: Its a Free Language — "Sean O'Halpin" <sean.ohalpin@...> 2009/02/01

On Sat, Jan 31, 2009 at 11:00 PM, Mike Stephens <rubfor@recitel.net> 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

39 messages 2009/01/29
[#326250] Re: RDoc 2.3 now with Darkfish, without CHM and extra HTML templates — Clifford Heath <no@...> 2009/01/30

Eric Hodel wrote:

[#326262] Re: RDoc 2.3 now with Darkfish, without CHM and extra HTML templates — James Gray <james@...> 2009/01/30

On Jan 30, 2009, at 5:27 AM, Clifford Heath wrote:

[#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

9 messages 2009/01/29

[#326241] Object#singleton_class in Ruby 1.9? — Suraj Kurapati <snk@...>

Hello,

48 messages 2009/01/30
[#326249] Re: Object#singleton_class in Ruby 1.9? — "David A. Black" <dblack@...> 2009/01/30

Hi --

[#326270] Re: Object#singleton_class in Ruby 1.9? — Yukihiro Matsumoto <matz@...> 2009/01/30

Hi,

[#326400] Re: Object#singleton_class in Ruby 1.9? — Robert Dober <robert.dober@...> 2009/01/31

On Fri, Jan 30, 2009 at 4:28 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

[#326415] Re: Object#singleton_class in Ruby 1.9? — Thomas Sawyer <transfire@...> 2009/01/31

Robert Dober wrote:

[#326460] Re: Object#singleton_class in Ruby 1.9? — "Sean O'Halpin" <sean.ohalpin@...> 2009/02/01

On Sat, Jan 31, 2009 at 8:03 PM, Thomas Sawyer <transfire@gmail.com> wrote:

[#326465] Re: Object#singleton_class in Ruby 1.9? — "David A. Black" <dblack@...> 2009/02/01

Hi --

[#326526] Re: Object#singleton_class in Ruby 1.9? — Thomas Sawyer <transfire@...> 2009/02/02

David A. Black wrote:

[#326276] Ruby 1.9.1 is released — "Yugui (Yuki Sonoda)" <yugui@...>

-----BEGIN PGP SIGNED MESSAGE-----

51 messages 2009/01/30

[#326412] Array#to_h — Roger Pack <rogerpack2005@...>

Not that I would find it useful at all, but is there is a Hash#to_a

19 messages 2009/01/31

[SUMMARY] Monopoly Walker (#188)

From: Matthew Moss <matt@...>
Date: 2009-01-22 21:26:00 UTC
List: ruby-talk #325643
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


In This Thread