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
| puts "what is the meaning of life?".slice(12, 7) | |
| # => meaning | |
| puts "what is the meaning of life?".slice(12, 7).concat(" can the universe really provide? ") | |
| # => meaning can the universe really provide? | |
| puts "what is the meaning of life?".slice(12, 7).concat(" can the universe really provide? ").reverse | |
| # => ?edivorp yllaer esrevinu eht nac gninaem | |
| puts "what is the meaning of life?".slice(12, 7).concat(" can the universe really provide? ").reverse.strip |
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
| def temperature_bot(temp) | |
| case temp | |
| when 18..21 | |
| "I like this temperature" | |
| else | |
| "This is uncomfortable for me" | |
| 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
| #create hash from array (a method) | |
| #parameters: an array of nested hashes | |
| #input | |
| items = [ {"AVOCADO" => {:price => 3.00, :clearance => true}}, | |
| {"KALE" => {:price => 3.00,:clearance => false}}, | |
| {"BLACK_BEANS" => {:price => 2.50,:clearance => false}}, | |
| {"ALMONDS" => {:price => 9.00, :clearance => false}}, | |
| {"TEMPEH" => {:price => 3.00,:clearance => true}}, |
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
| code = "fx1=ZY&iX3=ZW&hm5=ZU&dg7=ZS&ei9=ZQ&ge11=ZO&tr13=ZM&hh15=ZK&uX17=ZI&si19=ZG&tX21=ZE&Xn23=ZC&hp25=ZA&pX27=YY&dl29=YW&wo31=YU&XX33=YS&XX35=YQ&re37=YO&et39=YM&ia41=YK&wn43=YI&uo45=YG&dX47=YE&so49=YC&ec51=YA&do53=XY&sX55=XW&xr57=XU&so59=XS&aX61=XQ&ph63=XO&ni65=XM&nX67=XK&Xa69=XI&yX71=XG&aX73=XE&ei75=XC&ie0=ZZ&Xa2=ZX&Xy4=ZV&aX6=ZT&Xn8=ZR&in10=ZP&hp12=ZN&Xa14=ZL&os16=ZJ&rx18=ZH&Xs20=ZF&od22=ZD&ce24=ZB&os26=YZ&Xd28=YX&ou30=YV&nw32=YT&ai34=YR&te36=YP&er38=YN&XX40=YL&XX42=YJ&ow44=YH&ld46=YF&Xp48=YD&ph50=YB&nX52=XZ&Xt54=XX&is56=XV&Xu58=XT&hh60=XR&rt62=XP&eg64=XN&ie66=XL&gd68=XJ&mh70=XH&Xi72=XF&xf74=XD" | |
| chars = ('A'..'ZZ').to_a.reverse | |
| #tactic: | |
| #isolate the key-value pair, which is | |
| #ultimately, you combine hashes using the = Hash [key1, value1, key2, value2, key3, value3] | |
| def code_to_hash (code) | |
| code_split_again = [] |
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
| #solution 1 | |
| def prime1?(number) | |
| 2.upto(number-1) do |composite| | |
| return "#{number} is not prime" if number%composite == 0 | |
| end | |
| return "#{number} is prime" | |
| end | |
| #solution 2 |
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
| def myAll(myTeam) | |
| if block_given? | |
| myTeam.each do |pokemon| | |
| if !yield pokemon | |
| return false | |
| end | |
| end | |
| end | |
| return true | |
| 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 Jukebox | |
| attr_accessor :songs | |
| def welcome | |
| puts "Welcome to jukebox." | |
| end | |
| def instruction | |
| puts "What would you like to do? Please enter list, play, help, or exit" | |
| instruction = gets.downcase.chomp |
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
| # Testing / Assertion | |
| # Define a method that takes two values and compares them, printing pass or fail | |
| def assert_equal(actual, expected) | |
| if actual == expected | |
| return true | |
| else | |
| return false | |
| 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 'rubygems' | |
| require 'nokogiri' | |
| require 'open-uri' | |
| require 'sqlite3' | |
| def getname(webpage) | |
| name = webpage.search('h4.ib_main_header').children | |
| name.inner_text | |
| 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
| def reverse_each_word(sentence) | |
| print sentence.split.each {|word| word.reverse!}.join(" ") | |
| end | |
| reverse_each_word("Hello there, and how are you?") |