Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kchens/a6c0baee2fd69f9b43b7 to your computer and use it in GitHub Desktop.
Save kchens/a6c0baee2fd69f9b43b7 to your computer and use it in GitHub Desktop.
"Skinny" StockController - ServiceObject
# ######################
# Refactored
# ######################
# app/services/stock_service.rb
class StockService
def initialize(user)
@user = user
@stocks = []
@stock_symbols = []
end
def get_user_stock_symbols
@user.stocks.each do |stock|
@stock_symbols << stock.symbol
end
end
def update_stocks
@stock_symbols.each do |symbol|
@stocks << StockQuote::Stock.quote(symbol, nil, nil,
[ "Symbol",
"Name",
"LastTradePriceOnly"
] )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment