S
semmons99
Is there a simpler way to do the following?
<code>
Person = Struct.new( :first_name, :last_name )
print "Enter first name: "
first_name = gets.chomp.capitalize
print "Enter last name: "
last_name = gets.chomp.capitalize
p = Person.new( first_name, last_name )
printf "Hello %s %s.\n", p.first_name, p.last_name
</code>
My idea was to create a function the prints a message and then takes
console output. What I want to do is not have to create the extra
objects for first and last name. Below is the solution I can up with.
<code>
def pgets( msg )
print msg
gets
end
Person = Struct.new( :first_name, :last_name )
p = Person.new(
pgets( "Enter first name: " ).chomp.capitalize,
pgets( "Enter last name: " ).chomp.capitalize
)
printf "Hello %s %s.\n", p.first_name, p.last_name
</code>
Thanks,
Shane
<code>
Person = Struct.new( :first_name, :last_name )
print "Enter first name: "
first_name = gets.chomp.capitalize
print "Enter last name: "
last_name = gets.chomp.capitalize
p = Person.new( first_name, last_name )
printf "Hello %s %s.\n", p.first_name, p.last_name
</code>
My idea was to create a function the prints a message and then takes
console output. What I want to do is not have to create the extra
objects for first and last name. Below is the solution I can up with.
<code>
def pgets( msg )
print msg
gets
end
Person = Struct.new( :first_name, :last_name )
p = Person.new(
pgets( "Enter first name: " ).chomp.capitalize,
pgets( "Enter last name: " ).chomp.capitalize
)
printf "Hello %s %s.\n", p.first_name, p.last_name
</code>
Thanks,
Shane