This file contains 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 Lift | |
GROUND_FLOOR = 1 | |
TOTAL_FLOOR = 10 | |
@@previous_floor =0 | |
TRAVEL_TIME = 3 | |
DO_DC = 10 | |
attr_reader :elevator_on_floor | |
attr_accessor :elevator_target_floor, :new_floor |
This file contains 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
IO.puts "hello world!" |
This file contains 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
events/_forms.html.erb | |
<div class="form-group test"> | |
<%= f.label :auctions, class: "col-lg-4 col-sm-2 control-label required" %> | |
<div class="col-lg-8" id="filter"> | |
<%= f.collection_select :auction_ids, filter_auction, :id, :name, {}, {:multiple => true, class: "form-control acution-class", required: true}%> | |
</div> | |
</div> | |
<script> |
This file contains 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 Document | |
def average_word_length | |
total = 0.0 | |
words.each { |word| total += word.size } | |
total / word_count | |
end | |
end | |
#This is the kind of problem that the inject method is tailor-made to solve. Like each , inject takes a block and calls the | |
#block with each element of the collection. Unlike each , inject passes in two arguments to the block: Along with each |
This file contains 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
#The easiest way to screw up one of these iterating methods is to change the collection out from underneath the method. | |
#Here, for example, is a seriously misguided attempt to remove all of the negative numbers from an array: | |
array = [ 0, -10, -9, 5, 9 ] | |
array.each_index {|i| array.delete_at(i) if array[i] < 0} | |
pp array | |
#The trouble with this code is that it will tend to leave some negative numbers behind: Removing the first one (the -10 ) from | |
#the array messes up the internal indexing of the each method, so much that it will miss the second negative number, leaving | |
#us with a result of: |
This file contains 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
#Usual way | |
unique = [] | |
words.each { |word| unique << word unless unique.include?(word) } | |
#What we really need is a collection that doesn’t allow duplicates but does feature very fast and easy answers to the “is this | |
#object in there?” question. The punch line is that we need a set. Fortunately, Ruby comes with a perfectly serviceable, if | |
#sometimes forgotten, | |
#Set class: |
This file contains 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
#Be careful not to confuse chomp with the chop method. The chop method will simply knock off the last character of the | |
#string, no matter what it is | |
"hello\n".chomp | |
#=> "hello" | |
"hello".chomp | |
#=> "hello" | |
"hello".chop |
This file contains 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
puts 'yes yes'.sub( 'yes', 'no' ) | |
=> no yes | |
puts 'yes yes'.gsub( 'yes', 'no' ) | |
=> no no |
This file contains 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
Rspec:: | |
rspec | |
rspec spec/models | |
rspec spec/controllers/accounts_controller_spec.rb | |
rails generate rspec:model | |
/factories /support /models /controllers /features /views /mailers /routing /helpers | |
Model spec - behavior of model | |
require "rails_helper" |
This file contains 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
login with peer authondication | |
sudo -u postgres psql | |
login with md5 | |
Then type: | |
sudo -u postgres psql | |
Then: |
OlderNewer