Skip to content

Instantly share code, notes, and snippets.

View allolex's full-sized avatar
🏠
Working from home

Damon Davison allolex

🏠
Working from home
View GitHub Profile
# 1: Remove all hats. All are 0.
# 2: Every 2nd cat is switched to 1. [0, 1, 0, 1]
# 3: Every 3rd cat is switched (toggled). [0, 1, 1, 1]
# 4: [ 0, 1, 1, 0 ]
max = 100
cats = Array.new(max, 1)
p cats
# Print out a list of actions
def ask_action choices
puts "\n\nWhat do you want to do?"
puts choices
gets.chomp.downcase
end
def print_description(desc)
puts desc.gsub(/(?<=\A|\n)[ ]{2,}/,"")
end
def add_two number
return nil unless number.respond_to? :+
# if number.respond_to? :+
if number.respond_to? :concat
if number.respond_to? :push
number.push 2
else
number.concat "2"
end
expression = true
while (expression) do
80.times { puts }
puts "hello"
puts "enter your age:"
answer = gets.chomp
if answer.to_i > 20
# You're 21 or over
# Here we're demoing how puts and p work,
# as well as logging and commenting.
#1.+()
# puts "Hello World"
# p "Hello World!"
# p "Hello World!\n"
puts "This is the Ruby version (puts)"
puts RUBY_VERSION
puts "This is the Ruby version (p)"
# Here we're demoing how puts and p work,
# as well as logging and commenting.
#1.+()
# puts "Hello World"
# p "Hello World!"
# p "Hello World!\n"
puts "This is the Ruby version (puts)"
puts RUBY_VERSION
puts "This is the Ruby version (p)"
@allolex
allolex / 1.never_boolean.md
Created October 6, 2015 20:15 — forked from eddroid/1.never_boolean.md
Ruby Refactorings

Never Boolean

You hardly ever have to use the word true in your code.

if (something == true)
  # do something cool
end

Can be rewritten as

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<p>Bacon ipsum dolor amet landjaeger exercitation ullamco ea t-bone non pork
chop chuck cillum drumstick duis magna brisket laborum pork loin. Consequat
dolor shoulder, ham hock exercitation id velit aliquip dolore spare ribs
#!/usr/bin/env ruby
#
# Checks to see if the wirble gem is installed and
# installs it for you if it is not already installed.
def gem_list
@gem_list ||= `gem list`
end
def gem_name_re

Keybase proof

I hereby claim:

  • I am allolex on github.
  • I am curatur (https://keybase.io/curatur) on keybase.
  • I have a public key whose fingerprint is 4EC1 788F B843 E2D6 F422 0FC5 21AB 7510 79C4 8D8D

To claim this, I am signing this object: