[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

New user - very basic question

Ashley Wharton

2/7/2008 10:00:00 PM

[Note: parts of this message were removed to make it a legal post.]

Hi - sorry to bother with such a basic question, but is there a better way
to write the following: (before I move on I want to make sure I am following
best practice)

def require_number number_cur
puts number_cur
reply = gets.to_i

while reply < 100
reply = reply + 1
puts reply
end

if reply > 100
true
require_number 'Please enter a number less than 100: '
end
end
require_number 'Enter a number: '

Thanks so much!

10 Answers

Benjamin Stiglitz

2/7/2008 10:10:00 PM

0

Not elegant, but better:

def require_number(prompt, max)
print prompt
reply = gets.to_i
if reply >= max then reply = require_number "Please enter a number
less than #{max}: ", max end
reply
end

require_number 'Please enter a number: ', 100
--
Posted via http://www.ruby-....

Ashley Wharton

2/7/2008 10:43:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Feb 7, 2008 5:10 PM, Benjamin Stiglitz <ben@tanjero.com> wrote:

> Not elegant, but better:
>
> def require_number(prompt, max)
> print prompt
> reply = gets.to_i
> if reply >= max then reply = require_number "Please enter a number
> less than #{max}: ", max end
> reply
> end
>
> require_number 'Please enter a number: ', 100


Thank you for taking the time - could I trouble you further? If I want
the "reply" to iterate through until it reaches 100 could just add the
"while" to your code as below?

def require_number(prompt, max)
print prompt
reply = gets.to_i
if reply >= max then reply = require_number "Please enter a number
less than #{max}: ", max end
while reply < max
reply = reply + 1
puts reply
end
end
require_number 'Please enter a number: ', 100

>
> --
> Posted via http://www.ruby-....
>
>

Benjamin Stiglitz

2/7/2008 11:13:00 PM

0

> Thank you for taking the time - could I trouble you further? If I want
> the "reply" to iterate through until it reaches 100 could just add the
> "while" to your code as below?

> while reply < max
> reply = reply + 1
> puts reply
> end

Even better is
reply.upto(max - 1) { |x| puts x }

-Ben

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

Ashley Wharton

2/8/2008 1:15:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

Thank you very much! Take care,

ashley

On Feb 7, 2008 6:13 PM, Benjamin Stiglitz <ben@tanjero.com> wrote:

> > Thank you for taking the time - could I trouble you further? If I want
> > the "reply" to iterate through until it reaches 100 could just add the
> > "while" to your code as below?
>
> > while reply < max
> > reply = reply + 1
> > puts reply
> > end
>
> Even better is
> reply.upto(max - 1) { |x| puts x }
>
> -Ben
>
> --
> Posted via http://www.ruby-....
>
>

.MattB.

4/7/2012 3:25:00 AM

0

On Fri, 06 Apr 2012 21:18:56 -0600, RichTravsky
<traRvEsky@hotmMOVEail.com> wrote:

>Mike Flannigan wrote:
>> ".MattB." <trdell1234@Nomorespamgmail.com> wrote in message
>> > Iowa Republicans blast law school over refusal to hire conservative
>> > professor as faculty
>> > http://www.foxnews.com/us/2012/04/05/iowa-republicans-blast-law-school-over-refusal-to-hire-conservative-...
>> >
>> >
>> > Iowa Republicans are taking aim at the state's top law school for
>> > denying a faculty position to a conservative law professor, who an
>> > assistant dean once said embraces politics the rest of the faculty
>> > "despises."
>> >
>> > Teresa Wagner, who works as an associate director of writing at the
>> > University of Iowa College of Law, is suing former dean Carolyn Jones
>> > for employment discrimination, claiming she was not hired for a
>> > professor position because Jones and other law faculty disapproved of
>> > her conservative views and activism.
>> >
>> > To hold a law faculty position at the publicly funded university is
>> > viewed as a "sacred cow," Wagner said in an interview, and
>> > "Republicans need not apply."
>> >
>> > Heaven forbid student get a balanced education.
>>
>> This is why Hussein and the democrats want everyone to go to college, so
>> they can continue their liberal indoctrination. Does anyone sane believe
>> that they would fund someone who wanted to go to Hillsdale or Bob Jones with
>> their funding schemes for example? Shit no, and as an extra added bonus
>> feature you could put them out of business by making only the preferred
>> colleges free.
>>
>> -Eddie Haskell
>
>"As people do better, they start voting like Republicans... unless
>they have too much education and vote Democratic, which proves there
>can be too much of a good thing." - Karl Rove
>
>Republicons need 'em dumb.
>
>RT


Personally I think the extremes of both parties like them dumb.
Look at Richard and Zepp.

RichTravsky

4/7/2012 3:27:00 AM

0

".MattB." wrote:
>
> On Fri, 06 Apr 2012 21:18:56 -0600, RichTravsky
> <traRvEsky@hotmMOVEail.com> wrote:
>
> >Mike Flannigan wrote:
> >> ".MattB." <trdell1234@Nomorespamgmail.com> wrote in message
> >> > Iowa Republicans blast law school over refusal to hire conservative
> >> > professor as faculty
> >> > http://www.foxnews.com/us/2012/04/05/iowa-republicans-blast-law-school-over-refusal-to-hire-conservative-...
> >> >
> >> >
> >> > Iowa Republicans are taking aim at the state's top law school for
> >> > denying a faculty position to a conservative law professor, who an
> >> > assistant dean once said embraces politics the rest of the faculty
> >> > "despises."
> >> >
> >> > Teresa Wagner, who works as an associate director of writing at the
> >> > University of Iowa College of Law, is suing former dean Carolyn Jones
> >> > for employment discrimination, claiming she was not hired for a
> >> > professor position because Jones and other law faculty disapproved of
> >> > her conservative views and activism.
> >> >
> >> > To hold a law faculty position at the publicly funded university is
> >> > viewed as a "sacred cow," Wagner said in an interview, and
> >> > "Republicans need not apply."
> >> >
> >> > Heaven forbid student get a balanced education.
> >>
> >> This is why Hussein and the democrats want everyone to go to college, so
> >> they can continue their liberal indoctrination. Does anyone sane believe
> >> that they would fund someone who wanted to go to Hillsdale or Bob Jones with
> >> their funding schemes for example? Shit no, and as an extra added bonus
> >> feature you could put them out of business by making only the preferred
> >> colleges free.
> >>
> >> -Eddie Haskell
> >
> >"As people do better, they start voting like Republicans... unless
> >they have too much education and vote Democratic, which proves there
> >can be too much of a good thing." - Karl Rove
> >
> >Republicons need 'em dumb.
> >
> >RT
>
> Personally I think the extremes of both parties like them dumb.
> Look at Richard and Zepp.

Look at you. And Flannigan.

RT

.MattB.

4/7/2012 3:41:00 AM

0

On Fri, 06 Apr 2012 21:27:20 -0600, RichTravsky
<traRvEsky@hotmMOVEail.com> wrote:

>".MattB." wrote:
>>
>> On Fri, 06 Apr 2012 21:18:56 -0600, RichTravsky
>> <traRvEsky@hotmMOVEail.com> wrote:
>>
>> >Mike Flannigan wrote:
>> >> ".MattB." <trdell1234@Nomorespamgmail.com> wrote in message
>> >> > Iowa Republicans blast law school over refusal to hire conservative
>> >> > professor as faculty
>> >> > http://www.foxnews.com/us/2012/04/05/iowa-republicans-blast-law-school-over-refusal-to-hire-conservative-...
>> >> >
>> >> >
>> >> > Iowa Republicans are taking aim at the state's top law school for
>> >> > denying a faculty position to a conservative law professor, who an
>> >> > assistant dean once said embraces politics the rest of the faculty
>> >> > "despises."
>> >> >
>> >> > Teresa Wagner, who works as an associate director of writing at the
>> >> > University of Iowa College of Law, is suing former dean Carolyn Jones
>> >> > for employment discrimination, claiming she was not hired for a
>> >> > professor position because Jones and other law faculty disapproved of
>> >> > her conservative views and activism.
>> >> >
>> >> > To hold a law faculty position at the publicly funded university is
>> >> > viewed as a "sacred cow," Wagner said in an interview, and
>> >> > "Republicans need not apply."
>> >> >
>> >> > Heaven forbid student get a balanced education.
>> >>
>> >> This is why Hussein and the democrats want everyone to go to college, so
>> >> they can continue their liberal indoctrination. Does anyone sane believe
>> >> that they would fund someone who wanted to go to Hillsdale or Bob Jones with
>> >> their funding schemes for example? Shit no, and as an extra added bonus
>> >> feature you could put them out of business by making only the preferred
>> >> colleges free.
>> >>
>> >> -Eddie Haskell
>> >
>> >"As people do better, they start voting like Republicans... unless
>> >they have too much education and vote Democratic, which proves there
>> >can be too much of a good thing." - Karl Rove
>> >
>> >Republicons need 'em dumb.
>> >
>> >RT
>>
>> Personally I think the extremes of both parties like them dumb.
>> Look at Richard and Zepp.
>
>Look at you. And Flannigan.

LOL You are a joke here.
>
>RT

RichTravsky

4/9/2012 4:41:00 AM

0

".MattB." wrote:
> On Fri, 06 Apr 2012 21:27:20 -0600, RichTravsky
> <traRvEsky@hotmMOVEail.com> wrote:
> >".MattB." wrote:
> >> On Fri, 06 Apr 2012 21:18:56 -0600, RichTravsky
> >> <traRvEsky@hotmMOVEail.com> wrote:
> >> >Mike Flannigan wrote:
> >> >> ".MattB." <trdell1234@Nomorespamgmail.com> wrote in message
> >> >> > Iowa Republicans blast law school over refusal to hire conservative
> >> >> > professor as faculty
> >> >> > http://www.foxnews.com/us/2012/04/05/iowa-republicans-blast-law-school-over-refusal-to-hire-conservative-...
> >> >> >
> >> >> >
> >> >> > Iowa Republicans are taking aim at the state's top law school for
> >> >> > denying a faculty position to a conservative law professor, who an
> >> >> > assistant dean once said embraces politics the rest of the faculty
> >> >> > "despises."
> >> >> >
> >> >> > Teresa Wagner, who works as an associate director of writing at the
> >> >> > University of Iowa College of Law, is suing former dean Carolyn Jones
> >> >> > for employment discrimination, claiming she was not hired for a
> >> >> > professor position because Jones and other law faculty disapproved of
> >> >> > her conservative views and activism.
> >> >> >
> >> >> > To hold a law faculty position at the publicly funded university is
> >> >> > viewed as a "sacred cow," Wagner said in an interview, and
> >> >> > "Republicans need not apply."
> >> >> >
> >> >> > Heaven forbid student get a balanced education.
> >> >>
> >> >> This is why Hussein and the democrats want everyone to go to college, so
> >> >> they can continue their liberal indoctrination. Does anyone sane believe
> >> >> that they would fund someone who wanted to go to Hillsdale or Bob Jones with
> >> >> their funding schemes for example? Shit no, and as an extra added bonus
> >> >> feature you could put them out of business by making only the preferred
> >> >> colleges free.
> >> >>
> >> >> -Eddie Haskell
> >> >
> >> >"As people do better, they start voting like Republicans... unless
> >> >they have too much education and vote Democratic, which proves there
> >> >can be too much of a good thing." - Karl Rove
> >> >
> >> >Republicons need 'em dumb.
> >>
> >> Personally I think the extremes of both parties like them dumb.
> >> Look at Richard and Zepp.
> >
> >Look at you. And Flannigan.
>
> LOL You are a joke here.

I'm not the one whining about someone who bungled their interview...

RT

MattB.

4/9/2012 5:55:00 AM

0

On Sun, 08 Apr 2012 22:40:34 -0600, RichTravsky
<traRvEsky@hotmMOVEail.com> wrote:

>".MattB." wrote:
>> On Fri, 06 Apr 2012 21:27:20 -0600, RichTravsky
>> <traRvEsky@hotmMOVEail.com> wrote:
>> >".MattB." wrote:
>> >> On Fri, 06 Apr 2012 21:18:56 -0600, RichTravsky
>> >> <traRvEsky@hotmMOVEail.com> wrote:
>> >> >Mike Flannigan wrote:
>> >> >> ".MattB." <trdell1234@Nomorespamgmail.com> wrote in message
>> >> >> > Iowa Republicans blast law school over refusal to hire conservative
>> >> >> > professor as faculty
>> >> >> > http://www.foxnews.com/us/2012/04/05/iowa-republicans-blast-law-school-over-refusal-to-hire-conservative-...
>> >> >> >
>> >> >> >
>> >> >> > Iowa Republicans are taking aim at the state's top law school for
>> >> >> > denying a faculty position to a conservative law professor, who an
>> >> >> > assistant dean once said embraces politics the rest of the faculty
>> >> >> > "despises."
>> >> >> >
>> >> >> > Teresa Wagner, who works as an associate director of writing at the
>> >> >> > University of Iowa College of Law, is suing former dean Carolyn Jones
>> >> >> > for employment discrimination, claiming she was not hired for a
>> >> >> > professor position because Jones and other law faculty disapproved of
>> >> >> > her conservative views and activism.
>> >> >> >
>> >> >> > To hold a law faculty position at the publicly funded university is
>> >> >> > viewed as a "sacred cow," Wagner said in an interview, and
>> >> >> > "Republicans need not apply."
>> >> >> >
>> >> >> > Heaven forbid student get a balanced education.
>> >> >>
>> >> >> This is why Hussein and the democrats want everyone to go to college, so
>> >> >> they can continue their liberal indoctrination. Does anyone sane believe
>> >> >> that they would fund someone who wanted to go to Hillsdale or Bob Jones with
>> >> >> their funding schemes for example? Shit no, and as an extra added bonus
>> >> >> feature you could put them out of business by making only the preferred
>> >> >> colleges free.
>> >> >>
>> >> >> -Eddie Haskell
>> >> >
>> >> >"As people do better, they start voting like Republicans... unless
>> >> >they have too much education and vote Democratic, which proves there
>> >> >can be too much of a good thing." - Karl Rove
>> >> >
>> >> >Republicons need 'em dumb.
>> >>
>> >> Personally I think the extremes of both parties like them dumb.
>> >> Look at Richard and Zepp.
>> >
>> >Look at you. And Flannigan.
>>
>> LOL You are a joke here.
>
>I'm not the one whining about someone who bungled their interview...

I'm not the one pretending to know things like they were at the
interview. You're a liar plain and simple.

This will have one good result more Conservatives in Education.
That must really scare the Far left.

Conservatives should stop all funding to schools that hire based on
Political views.


>
>RT

RichTravsky

4/11/2012 3:32:00 AM

0

"MattB." wrote:
>
> On Sun, 08 Apr 2012 22:40:34 -0600, RichTravsky
> <traRvEsky@hotmMOVEail.com> wrote:
>
> >".MattB." wrote:
> >> On Fri, 06 Apr 2012 21:27:20 -0600, RichTravsky
> >> <traRvEsky@hotmMOVEail.com> wrote:
> >> >".MattB." wrote:
> >> >> On Fri, 06 Apr 2012 21:18:56 -0600, RichTravsky
> >> >> <traRvEsky@hotmMOVEail.com> wrote:
> >> >> >Mike Flannigan wrote:
> >> >> >> ".MattB." <trdell1234@Nomorespamgmail.com> wrote in message
> >> >> >> > Iowa Republicans blast law school over refusal to hire conservative
> >> >> >> > professor as faculty
> >> >> >> > http://www.foxnews.com/us/2012/04/05/iowa-republicans-blast-law-school-over-refusal-to-hire-conservative-...
> >> >> >> >
> >> >> >> >
> >> >> >> > Iowa Republicans are taking aim at the state's top law school for
> >> >> >> > denying a faculty position to a conservative law professor, who an
> >> >> >> > assistant dean once said embraces politics the rest of the faculty
> >> >> >> > "despises."
> >> >> >> >
> >> >> >> > Teresa Wagner, who works as an associate director of writing at the
> >> >> >> > University of Iowa College of Law, is suing former dean Carolyn Jones
> >> >> >> > for employment discrimination, claiming she was not hired for a
> >> >> >> > professor position because Jones and other law faculty disapproved of
> >> >> >> > her conservative views and activism.
> >> >> >> >
> >> >> >> > To hold a law faculty position at the publicly funded university is
> >> >> >> > viewed as a "sacred cow," Wagner said in an interview, and
> >> >> >> > "Republicans need not apply."
> >> >> >> >
> >> >> >> > Heaven forbid student get a balanced education.
> >> >> >>
> >> >> >> This is why Hussein and the democrats want everyone to go to college, so
> >> >> >> they can continue their liberal indoctrination. Does anyone sane believe
> >> >> >> that they would fund someone who wanted to go to Hillsdale or Bob Jones with
> >> >> >> their funding schemes for example? Shit no, and as an extra added bonus
> >> >> >> feature you could put them out of business by making only the preferred
> >> >> >> colleges free.
> >> >> >>
> >> >> >> -Eddie Haskell
> >> >> >
> >> >> >"As people do better, they start voting like Republicans... unless
> >> >> >they have too much education and vote Democratic, which proves there
> >> >> >can be too much of a good thing." - Karl Rove
> >> >> >
> >> >> >Republicons need 'em dumb.
> >> >>
> >> >> Personally I think the extremes of both parties like them dumb.
> >> >> Look at Richard and Zepp.
> >> >
> >> >Look at you. And Flannigan.
> >>
> >> LOL You are a joke here.
> >
> >I'm not the one whining about someone who bungled their interview...
>
> I'm not the one pretending to know things like they were at the
> interview. You're a liar plain and simple.

You didn't follow the Faux News link, I see.

> This will have one good result more Conservatives in Education.
> That must really scare the Far left.
>
> Conservatives should stop all funding to schools that hire based on
> Political views.
>
> >
> >RT