# Mexican Blanket (#127) Problem

**URL:** <https://www.ruby-forum.com/t/mexican-blanket-127-problem/225952>\
**Category:** Ruby\
**Created:** [June 18, 2007, 1:01am UTC](https://www.ruby-forum.com/t/mexican-blanket-127-problem/225952 "2007-06-18T01:01:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [June 18, 2007, 1:01am UTC](https://www.ruby-forum.com/t/mexican-blanket-127-problem/225952/1 "2007-06-18T01:01:29Z")

</div>

Hey all,  
I was attempting Mexican Blanket today, and found it to be more of a  
brain teaser (for me) than a coding problem.

Which doesn’t mean there were no coding problems.

I keep getting an error for the Integer#times method. I think I’m  
using it right, but could someone help me correct it please?

Also, do I have my shebang setup correctly to type ./  
mexican\_blanket.rb ETC and have it run? Because I can never seem to  
get it to work.

------------------------------------------------------------------|  
Error  
------------------------------------------------------------------|  
mexican\_blanket.rb:21:in `weave': undefined method`times’ for  
“25”:String (NoMethodError)  
from mexican\_blanket.rb:15:in `initialize' from mexican_blanket.rb:49:in`new’  
from mexican\_blanket.rb:49

------------------------------------------------------------------|  
Code  
------------------------------------------------------------------|  
#!/usr/bin/ruby  
#this one is just a test thing. Not gonna do the designs diagonally

class Blanket

def initialize(colors, length, width, pattern\_length)  
@COLORS = colors.split(//)  
@LENGTH = length  
@WIDTH = width  
@slot = -1  
@SLOTS = @COLORS.length  
@PL = pattern\_length  
@mainp = pattern\_length  
@offp = 1  
weave()  
end

def weave() # THIS IS LINE 15  
@LENGTH.times do |i|  
@mainp.times { #build the PATTERN long…  
@slot = (@slot + 1)  
width\_ticker = 0  
until width\_ticker == @WIDTH#build it wide…  
print ‘#{@COLOR[(@slot % @SLOTS)]}’  
width\_ticker = width\_ticker + 1  
ticker = ticker + 1  
end  
}  
end

```
 @offp.times do |i|
   @slot = (@slot + 1)
   width_ticker = 0
   until width_ticker == @WIDTH #build it wide...
     print '#{@COLOR[(@slot % @slots)]}'
     width_ticker = width_ticker + 1
     ticker = ticker + 1
   end
 end
 @mainp = (@mainp + (@PL - 1)) % @PL
 @offp = @offp.next % @PL

```

end  
end

colors = ARGV[0]  
length = ARGV[1]  
width = ARGV[2]  
pattern\_length = ARGV[3]  
mexico = Blanket.new(colors, length, width, pattern\_length) #THIS  
IS LINE 49  
#end  
-------------------------------------------|  
~aRi  
I did my version of it as a top-down pattern as opposed to a diagonal  
pattern.

---

<div class="post-metadata">

**Author:** ![Ari\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@Ari\_B](https://www.ruby-forum.com/u/Ari_B)\
**Post date:** [June 18, 2007, 3:01am UTC](https://www.ruby-forum.com/t/mexican-blanket-127-problem/225952/2 "2007-06-18T03:01:37Z")

</div>

On 6/18/07, Ari B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> mexican\_blanket.rb:21:in `weave': undefined method `times’ for  
> “25”:String (NoMethodError)  
> from mexican\_blanket.rb:15:in `initialize' from mexican_blanket.rb:49:in `new’  
> from mexican\_blanket.rb:49
> 
> ------------------------------------------------------------------|

It looks like “25” is a String. You need to change it to an Integer.

colors = ARGV[0]  
length = ARGV[1]  
width = ARGV[2]  
pattern\_length = ARGV[3]  
p width.class # Add this line and take a look

mexico = Blanket.new(colors, length, width, pattern\_length)

You may want to check the others, too.

Harry

–

A Look into Japanese Ruby List in English  
[http://www.kakueki.com/](http://www.kakueki.com/)
