From bbae197ed14dd264322fe8db2e500e2ce7b36765 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Fri, 16 Mar 2018 08:58:07 -0400 Subject: [PATCH] better ternary and using symbols instead of quotes to access options hash --- app/models/fruit.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/fruit.rb b/app/models/fruit.rb index a0cfa72..8e11a89 100644 --- a/app/models/fruit.rb +++ b/app/models/fruit.rb @@ -10,7 +10,7 @@ class Fruit @id = opts["id"].to_i @name = opts["name"] @color = opts["color"] - @readyToEat = (opts["readytoeat"]=='t')?true:false + @readyToEat = (opts["readytoeat"]=='t') ? true : false end def self.all @@ -24,7 +24,7 @@ class Fruit end def self.create(opts={}) - results = DB.exec("INSERT INTO fruits (name, color, readytoeat) VALUES ( '#{opts["name"]}', '#{opts["color"]}', #{opts["readyToEat"]} );") + results = DB.exec("INSERT INTO fruits (name, color, readytoeat) VALUES ( '#{opts[:name]}', '#{opts[:color]}', #{opts[:readyToEat]} );") return { created: true } end @@ -34,7 +34,7 @@ class Fruit end def self.update(id, opts={}) - results = DB.exec("UPDATE fruits SET name='#{opts["name"]}', color='#{opts["color"]}', readytoeat=#{opts["readyToEat"]} WHERE id=#{id} ;") + results = DB.exec("UPDATE fruits SET name='#{opts[:name]}', color='#{opts[:color]}', readytoeat=#{opts[:readyToEat]} WHERE id=#{id} ;") return { updated: true } end end