Default text entered in a puts dialog

Discussion in 'Ruby' started by 12 34, Jun 20, 2007.

  1. 12 34

    12 34 Guest

    I want to put a default answer in the text entry box that appears when
    you puts some text.

    photoGMT = -4
    puts "What time zone are the photos in?"
    answer = gets.chomp.to_i

    I'd like photoGMT to appear as a default answer. I know this wouldn't be
    very convenient in Terminal, but works well with TextMate.

    For ASers this is equivalent to

    set photoGMT to -4
    display dialog "What time zone are the photos in?" default answer
    photoGMT

    --
    Posted via http://www.ruby-forum.com/.
     
    12 34, Jun 20, 2007
    #1
    1. Advertising

  2. 12 34

    Jano Svitok Guest

    On 6/20/07, 12 34 <> wrote:
    > I want to put a default answer in the text entry box that appears when
    > you puts some text.
    >
    > photoGMT = -4
    > puts "What time zone are the photos in?"
    > answer = gets.chomp.to_i
    >
    > I'd like photoGMT to appear as a default answer. I know this wouldn't be
    > very convenient in Terminal, but works well with TextMate.
    >
    > For ASers this is equivalent to
    >
    > set photoGMT to -4
    > display dialog "What time zone are the photos in?" default answer
    > photoGMT


    This is the best I can imagine: you cannot fill the input buffer
    easily, so I propose to use the default value if the reply is empty.

    photoGMT = -4
    puts "What time zone are the photos in? [#{photoGMT}]"
    ans = gets.strip
    answer = ans.empty? ? photoGMT : ans.to_i


    Jano
     
    Jano Svitok, Jun 20, 2007
    #2
    1. Advertising

  3. 12 34

    12 34 Guest

    Jano Svitok wrote:
    > On 6/20/07, 12 34 <> wrote:
    >> For ASers this is equivalent to
    >>
    >> set photoGMT to -4
    >> display dialog "What time zone are the photos in?" default answer
    >> photoGMT

    >
    > This is the best I can imagine: you cannot fill the input buffer
    > easily, so I propose to use the default value if the reply is empty.
    >
    > photoGMT = -4
    > puts "What time zone are the photos in? [#{photoGMT}]"
    > ans = gets.strip
    > answer = ans.empty? ? photoGMT : ans.to_i
    >
    >
    > Jano


    TextMate errors on strip. I change to chomp and TextMate errors on empty
    field. Works OK if the field is filled in.

    Thanks for trying.

    --
    Posted via http://www.ruby-forum.com/.
     
    12 34, Jun 20, 2007
    #3
  4. On Jun 20, 2007, at 2:32 PM, 12 34 wrote:

    > Jano Svitok wrote:
    >> On 6/20/07, 12 34 <> wrote:
    >>> For ASers this is equivalent to
    >>>
    >>> set photoGMT to -4
    >>> display dialog "What time zone are the photos in?" default answer
    >>> photoGMT

    >>
    >> This is the best I can imagine: you cannot fill the input buffer
    >> easily, so I propose to use the default value if the reply is empty.
    >>
    >> photoGMT =3D -4
    >> puts "What time zone are the photos in? [#{photoGMT}]"
    >> ans =3D gets.strip
    >> answer =3D ans.empty? ? photoGMT : ans.to_i
    >>
    >>
    >> Jano

    >
    > TextMate errors on strip. I change to chomp and TextMate errors on =20
    > empty
    > field. Works OK if the field is filled in.


    I ran the above code in TextMate with Run (cmd-R) and it worked fine. =20=

    It only failed when I tried to execute it with Execute and Update =91# =20=

    =3D>=92 Markers (ctl-shift-cmd-E). Did you execute with Run or with =20
    Execute ...?

    Regards, Morton
     
    Morton Goldberg, Jun 20, 2007
    #4
  5. 12 34

    12 34 Guest

    Morton Goldberg wrote:
    > On Jun 20, 2007, at 2:32 PM, 12 34 wrote:
    >
    >>>

    >> field. Works OK if the field is filled in.

    > I ran the above code in TextMate with Run (cmd-R) and it worked fine.
    > It only failed when I tried to execute it with Execute and Update �#
    > =>� Markers (ctl-shift-cmd-E). Did you execute with Run or with
    > Execute ...?
    >
    > Regards, Morton


    An update fixed the problem.

    --
    Posted via http://www.ruby-forum.com/.
     
    12 34, Jun 21, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TN Bella
    Replies:
    1
    Views:
    1,550
    TN Bella
    Jul 1, 2004
  2. =?Utf-8?B?U2FuZHk=?=
    Replies:
    3
    Views:
    765
    fd123456
    Feb 12, 2005
  3. Michael Brooks
    Replies:
    22
    Views:
    435
    Rick DeNatale
    Mar 27, 2007
  4. Raj Singh
    Replies:
    4
    Views:
    155
    Ryan Ingram
    Jan 29, 2008
  5. cmgmyr

    Add new text box after entered text

    cmgmyr, May 25, 2008, in forum: Javascript
    Replies:
    1
    Views:
    127
    cmgmyr
    May 27, 2008
Loading...

Share This Page