utility.rb
# Prints the contents of the array using the format string fmt_str but adds
# natural english connectives. fmt_str must use self as the interpolation
# variable, and should be escaped accordingly
Prints the contents of the array using the format string fmt_str but adds
natural english connectives. fmt_str must use self as the interpolation
variable, and should be escaped accordingly
Prints the contents of the array using the format string fmt_str but adds natural english connectives . fmt_str must use self as the interpolation variable and should be escaped accordingly
def format_list(array, fmt_str)
  str = ""
  array.each.with_index do |x, i|
    if array.length == 1
      x.instance_eval("str << \"#{fmt_str}\"")
    elsif i == array.length - 1
      x.instance_eval("str << \"and #{fmt_str}\"")
    else
      x.instance_eval("str << \"#{fmt_str}, \"")
    end
  end
  str
end
def format_list ( array , fmt_str ) str = "" array . each . with_index do | x , i | if array . length == 1 x . instance_eval ( "str << \"#{fmt_str}\"" ) elsif i == array . length - 1 x . instance_eval ( "str << \"and #{fmt_str}\"" ) else x . instance_eval ( "str << \"#{fmt_str}, \"" ) end end str end
Prints the contents of the array using the format string fmt_str but adds
natural english connectives.
Prints the contents of the array using the format string fmt_str but adds natural english connectives .
array
fmt_str