Timeline for Lottery number generator
Current License: CC BY-SA 3.0
14 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 22, 2015 at 0:37 | history | edited | Mark Thomas | CC BY-SA 3.0 |
added 42 characters in body
|
| Feb 21, 2015 at 23:55 | comment | added | Frommel | Though the class stuff is a little bit extended on the initial question, I found it useful. | |
| Feb 21, 2015 at 23:51 | comment | added | Mark Thomas |
Yep, that's why I said "here's a start". I offered a minimal class to show things like class attributes, the initialize method, etc. Giving it more functionality is an exercise left to the reader :)
|
|
| Feb 21, 2015 at 23:45 | comment | added | Frommel | I think what 200_success is trying to say, that u made a class that represents a lottery, not a lottery ticket. Meaning if we draw 6 balls, we might want to be able to to look at those numbers at some point later. Therefore we should save the six numbers and return those on a pick call or even providing seperate methods for last_draw and new_draw. | |
| Feb 21, 2015 at 23:42 | comment | added | Mark Thomas | @Frommel If you're referring to the default value of a parameter, the answer is yes. The pick method in my example defaults to 1. | |
| Feb 21, 2015 at 23:40 | comment | added | Mark Thomas |
@200_success I'm not sure what you mean. The pick method represents a lottery ticket. If we both go to the store and buy a ticket, we could end up with some of the same numbers, no?
|
|
| Feb 21, 2015 at 23:39 | comment | added | Frommel | Thank you very much. One question though just to be sure: in the method definition i can even declare a standard value for my parameters. Is that right? | |
| Feb 21, 2015 at 23:38 | comment | added | 200_success |
I would expect the object to be stateful. In other words, successive calls to pick on the same object should not result in duplicates. Otherwise, there is no advantage over the simple function.
|
|
| Feb 21, 2015 at 23:35 | comment | added | Mark Thomas | I added another option, using a class. | |
| Feb 21, 2015 at 23:33 | comment | added | Mark Thomas | Indeed! You would be surprised the number of things that can be boiled down to 2 lines. Developers coming from other languages are surprised to hear guidelines like methods should be no longer than 5 lines but it is not only possible, it is truly better: that conciseness often increases clarity. | |
| Feb 21, 2015 at 23:24 | history | edited | Mark Thomas | CC BY-SA 3.0 |
added 206 characters in body
|
| Feb 21, 2015 at 23:02 | comment | added | Frommel | Wow I'm stunned. So basically we got down to 2 lines of instructions. I begin to grasp the potential of ruby. :) | |
| Feb 21, 2015 at 22:46 | history | edited | Mark Thomas | CC BY-SA 3.0 |
added 206 characters in body
|
| Feb 21, 2015 at 22:39 | history | answered | Mark Thomas | CC BY-SA 3.0 |