This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
def generate_users | |
query = "SELECT first_name, last_name FROM users" | |
sanitized_query = ActiveRecord::Base.sanitize_sql_array([query]) | |
result = ActiveRecord::Base.connection.execute(sanitized_query).values | |
csv_string = CSV.generate do |csv| | |
csv << ["first_name", "last_name"] | |
result.map { |row| csv << row } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "animal" | |
class Warthog < Animal | |
def talk | |
"#{name} grunts !" | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "animal" | |
class Meerkat < Animal | |
def talk | |
"#{name} barks !" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "animal" | |
class Lion < Animal | |
def talk | |
"#{name} roars !" | |
end | |
def eat(food) | |
super(food) + ". Law of the jungle!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "lion" | |
require_relative "meerkat" | |
require_relative "warthog" | |
my_lion = Lion.new("simba") | |
timon = Meerkat.new("timon") | |
pumba = Warthog.new("pumba") | |
[my_lion, timon, pumba].each do |animal| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
def self.phyla | |
%w[ | |
Ecdysozoa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'building' | |
require_relative 'butler' | |
class House < Building | |
attr_accessor :butler | |
def initialize(name, width, length, butler_name) | |
super(name, width, length) | |
@butler = Butler.new(butler_name, self) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'building' | |
require_relative 'butler' | |
class Castle < Building | |
attr_accessor :butler | |
def initialize(name, width, length, butler_name) | |
super(name, width, length) | |
@butler = Butler.new(butler_name, self) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Butler | |
attr_reader :name, :associated_house | |
def initialize(name, associated_house) | |
@name = name | |
@associated_house = associated_house | |
end | |
def clean_associated_house | |
puts "#{associated_house.name} cleaned by #{name} !" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Building | |
attr_reader :width, :length | |
attr_accessor :name | |
def initialize(name, width, length) | |
@name = name | |
@width = width | |
@length = length | |
end |
NewerOlder