FAQ
Hello,

I have to make a exception part on triangles now.

The exercise looks like this :
[/code]
**# You need to write the triangle method in the file 'triangle.rb'
require 'triangle.rb'

class AboutTriangleProject2 < EdgeCase::Koan
# The first assignment did not talk about how to handle errors.
# Let's handle that part now.
def test_illegal_triangles_throw_exceptions
assert_raise(TriangleError) do triangle(0, 0, 0) end
assert_raise(TriangleError) do triangle(3, 4, -5) end
assert_raise(TriangleError) do triangle(1, 1, 3) end
assert_raise(TriangleError) do triangle(2, 4, 2) end
# HINT: for tips, see
http://stackoverflow.com/questions/3834203/ruby-koan-151-raising-exceptions
end
end
[/code]

So I looked at that page and come with this solution :
[code]
def triangle(a, b, c)

raise TriangleError, "length cannnot be 0 or lesser" if (a <= 0) or (b <=
0) or (c <= 0);
raise TriangleError, "length does not mach Pyschotorogas" if (a * a + b *
b != c * c);

return :equilateral if ((a == b) and (b == c))
return :isosceles if (((a == b) and (b != c)) or
((a != b) and (b == c)) or
((a == c) and (a != b)))
return :scalene if ((a !=b) and (b != c))
end
[/code]

But now I get a uninitialized constant TriangleError

What did I do wrong now ?

Roelof

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/gpwo2gOeHJ0J.
For more options, visit https://groups.google.com/groups/opt_out.

## Search Discussions

• at Sep 22, 2012 at 5:09 pm ⇧ Hello,

I found this solution :

# about_triangle_project.rb
# and
# about_triangle_project_2.rb
#
def triangle(a, b, c)

raise (TriangleError), "length cannnot be 0 or lesser" if (a <= 0) or (b
<= 0) or (c <= 0);
raise (TriangleError), "length does not match Pyschotorogas" if (a * a +
b * b != c * c);

return :equilateral if ((a == b) and (b == c))
return :isosceles if (((a == b) and (b != c)) or
((a != b) and (b == c)) or
((a == c) and (a != b)))
return :scalene if ((a !=b) and (b != c))
end

# Error class used in part 2. No need to change this code.
class TriangleError < StandardError
end

But now when a error is found the script is stopped. Can anyone give me a
hint how I can continue this script.

Roelof

Op zaterdag 22 september 2012 16:43:03 UTC+2 schreef roelof het volgende:
Hello,

I have to make a exception part on triangles now.

The exercise looks like this :
[/code]
**# You need to write the triangle method in the file 'triangle.rb'
require 'triangle.rb'

class AboutTriangleProject2 < EdgeCase::Koan
# The first assignment did not talk about how to handle errors.
# Let's handle that part now.
def test_illegal_triangles_throw_exceptions
assert_raise(TriangleError) do triangle(0, 0, 0) end
assert_raise(TriangleError) do triangle(3, 4, -5) end
assert_raise(TriangleError) do triangle(1, 1, 3) end
assert_raise(TriangleError) do triangle(2, 4, 2) end
# HINT: for tips, see
http://stackoverflow.com/questions/3834203/ruby-koan-151-raising-exceptions
end
end
[/code]

So I looked at that page and come with this solution :
[code]
def triangle(a, b, c)

raise TriangleError, "length cannnot be 0 or lesser" if (a <= 0) or (b
<= 0) or (c <= 0);
raise TriangleError, "length does not mach Pyschotorogas" if (a * a + b
* b != c * c);

return :equilateral if ((a == b) and (b == c))
return :isosceles if (((a == b) and (b != c)) or
((a != b) and (b == c)) or
((a == c) and (a != b)))
return :scalene if ((a !=b) and (b != c))
end
[/code]

But now I get a uninitialized constant TriangleError

What did I do wrong now ?

Roelof

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/89jOvtdDMDwJ.
For more options, visit https://groups.google.com/groups/opt_out.
• at Sep 23, 2012 at 3:12 pm ⇧ 1) Very good. Now you should try to determine what "Ruby on Rails" is,
and whether your questions have anything to do with Ruby on Rails.

2) Read a tutorial on ruby exception handling, or better yet buy the
book "Beginning Ruby":

http://beginningruby.org/

and read that before trying to do the koans. All you seem to be doing
is copying other people's code, so what good does that do you?

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

## Related Discussions

Discussion Navigation
 view thread | post
Discussion Overview
 group rubyonrails-talk categories rubyonrails posted Sep 22, '12 at 2:43p active Sep 23, '12 at 3:12p posts 3 users 2 website rubyonrails.org irc #RubyOnRails

### 2 users in discussion

Content

People

Support

Translate

site design / logo © 2021 Grokbase