# Default text entered in a puts dialog

**URL:** <https://www.ruby-forum.com/t/default-text-entered-in-a-puts-dialog/107350>\
**Category:** Ruby\
**Created:** [June 20, 2007, 7:52pm UTC](https://www.ruby-forum.com/t/default-text-entered-in-a-puts-dialog/107350 "2007-06-20T19:52:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtnbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@mtnbiker](https://www.ruby-forum.com/u/mtnbiker)\
**Post date:** [June 20, 2007, 7:52pm UTC](https://www.ruby-forum.com/t/default-text-entered-in-a-puts-dialog/107350/1 "2007-06-20T19:52:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mtnbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@mtnbiker](https://www.ruby-forum.com/u/mtnbiker)\
**Post date:** [June 20, 2007, 8:09pm UTC](https://www.ruby-forum.com/t/default-text-entered-in-a-puts-dialog/107350/2 "2007-06-20T20:09:26Z")

</div>

On 6/20/07, 12 34 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![mtnbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@mtnbiker](https://www.ruby-forum.com/u/mtnbiker)\
**Post date:** [June 20, 2007, 8:32pm UTC](https://www.ruby-forum.com/t/default-text-entered-in-a-puts-dialog/107350/3 "2007-06-20T20:32:05Z")

</div>

Jano S. wrote:

> On 6/20/07, 12 34 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![mtnbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@mtnbiker](https://www.ruby-forum.com/u/mtnbiker)\
**Post date:** [June 21, 2007, 12:37am UTC](https://www.ruby-forum.com/t/default-text-entered-in-a-puts-dialog/107350/4 "2007-06-21T00:37:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mtnbiker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@mtnbiker](https://www.ruby-forum.com/u/mtnbiker)\
**Post date:** [June 21, 2007, 2:35am UTC](https://www.ruby-forum.com/t/default-text-entered-in-a-puts-dialog/107350/5 "2007-06-21T02:35:06Z")

</div>

Morton G. 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.
