Skip to content

Instantly share code, notes, and snippets.

class CaesarCipher
attr_accessor :shift_value
def initialize(shift_value)
@shift_value = shift_value
@shifted_alphabet_array = ("A".."Z").to_a.rotate(@shift_value)
@alphabet_array = ("A".."Z").to_a
end
def cipher(text)
text.upcase.split("").each_with_object("") do |chr, cipher_text|
@bjhaid
bjhaid / gist:6460526
Created September 6, 2013 07:16
method_missing blowing up
2.0.0p247 :001 > def method_missing m,*args; [m.to_s,args].flatten.join " "; end
=> nil
2.0.0p247 :002 > "j".happy "hh"
2.0.0p247 :001 > def method_missing *args; args.join " "; end
=> nil
2.0.0p247 :002 > "j".happy
SystemStackError: stack level too deep
from /Users/bjhaid/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/irb/workspace.rb:86
Maybe IRB bug!
@bjhaid
bjhaid / hellword_spec.rb
Last active December 22, 2015 09:39
helloworld Rspec
require 'helloworld'
describe Helloworld do
it "should say 'HelloWorld!'" do
helloWorld = Helloworld.new()
helloWorld.hello.should eql("HelloWorld!")
end
end
Index:
1. should() #basic expectation
2. should_not() #basic negation of an expectation (RSpec does not support using !=)
3. include(item) #called on an enumerable object, this returns true or false if the object is found in the enumerable collection
4. respond_to(:message) #determines if a particular message (as a symbol) is defined for an object
5. raise_error(type, message) #checks if a particular error was raised, accepts zero, one or two parameters
@bjhaid
bjhaid / scary_craps.rb
Last active December 20, 2015 19:09 — forked from kaplan/scary_craps.rb
class Die
def roll
rand(1..6)
end
end
class Player
attr_writer :die1, :die2
def initialize
@dice_roll_from_first_turn = nil
@bjhaid
bjhaid / gist:6165069
Created August 6, 2013 14:38
rvm install 1.9.3 --debug
$ rvm install 1.9.3 --debug
1.9.3 - install
Searching for binary rubies, this might take some time.
Remote file does not exist https://rvm.io/binaries/mint/15/x86_64/ruby-1.9.3-p448.tar.bz2
Remote file does not exist http://jruby.org.s3.amazonaws.com/downloads/ruby-1.9.3-p448.tar.bz2
Remote file does not exist http://binaries.rubini.us/mint/15/x86_64/ruby-1.9.3-p448.tar.bz2
rvm_remote_server_url3 not found
No remote file name found
No binary rubies available for: mint/15/x86_64/ruby-1.9.3-p448.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
@bjhaid
bjhaid / tapan.rb
Created March 20, 2013 08:08
Test script for Tapan
puts "I love Ruby so so much"
sleep 5
puts("\n" * 3)
puts "Welcome to Ruby"
@bjhaid
bjhaid / Answers
Last active December 11, 2015 23:08
Ruby Assignment for Kenny
#1. Write a script that would request for a person's name, age, home address, and print it to console in the format:
My name is Ayodele Abejide, I am 29 years old, I live in Gbagada, Lagos, Nigeria.
print "What is your name? "
name = gets.chomp
print "How old are you? "
age = gets.chomp
print "Where do you live? "
home_address = gets.chomp
private RIMXMLResponseDetail processRIMResponse(String response)
{
RIMXMLResponseDetail rimXMLResponseDetail = new RIMXMLResponseDetail();
try
{
document = DocumentHelper.parseText(response);
if ( document.selectSingleNode("//ProvisioningReply/Body/ProvisioningEntity/ProvisioningDataItem[@name='BillingId']") == null){
Node billingID = document.selectSingleNode("//ProvisioningReply/Body/ProvisioningEntity/ProvisioningDataItem[@name='IMSI']");
rimXMLResponseDetail.setImsi(billingID.getText());
have_library: checking for t_open() in -lnsl... -------------------- no
"gcc -o conftest -I/usr/local/include/ruby-1.9.1/x86_64-linux -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I. -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -L/usr/local/lib -Wl,-R/usr/local/lib -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/usr/local/lib -L/usr/local/lib -lruby-static -lpthread -lrt -ldl -lcrypt -lm -lc"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */