Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 98964f918139f5329e1483c2e28c480c92225e46 @adamhunter committed Sep 19, 2012
Showing with 308 additions and 0 deletions.
  1. +1 −0 .rspec
  2. +15 −0 README.md
  3. +134 −0 main.rb
  4. +158 −0 slides.rb
1 .rspec
@@ -0,0 +1 @@
+--color
@@ -0,0 +1,15 @@
+# Ruby 101
+
+This is a command line utility that will run the presentation through IRB.
+
+## Usage
+
+```bash
+ ruby main.rb
+```
+
+This will drop you into an IRB session with an instance variable called `@deck`.
+
+```ruby
+ @deck.play
+```
134 main.rb
@@ -0,0 +1,134 @@
+#!/usr/bin/env ruby
+
+$:.unshift('.')
+
+require 'irb'
+require 'artii'
+require 'colorize'
+
+module String::ToAscii
+ def to_ascii
+ @artii ||= Artii::Base.new
+ @artii.asciify(self)
+ end
+end
+
+String.send(:include, String::ToAscii)
+
+class SlideDeck
+ def initialize(slides)
+ @played = []
+ @slides = slides.dup
+ end
+
+ def play
+ puts "\n#{self.next}\n"
+ end
+
+ def next
+ slides.shift.tap { |slide| played.push(slide) }
+ end
+
+ def prev
+ played.pop.tap { |slide| slides.unshift(slide) }
+ end
+
+ def peek
+ slides.first
+ end
+
+ def rewind
+ prev until played.empty?
+ true
+ end
+
+ def fast_forward
+ self.next until slides.one?
+ true
+ end
+ alias :ff :fast_forward
+
+ def inspect
+ "#<SlideDeck @slides @played>"
+ end
+
+ private
+
+ def slides
+ @slides.compact!
+ @slides
+ end
+
+ def played
+ @played.compact!
+ @played
+ end
+end
+
+def reload!
+ $stdout.puts "Loading Ruby 101 environment...\n\n"
+ Object.send(:remove_const, :SLIDES) if Object.const_defined?(:SLIDES)
+ $LOADED_FEATURES.delete(File.expand_path('./slides.rb'))
+ require 'slides'
+ @deck = SlideDeck.new(SLIDES)
+end
+
+reload!
+
+unless defined?(RSpec)
+ IRB.start
+
+else
+ describe "my presentation" do
+ let(:sentence) { %[Why is Ruby Awesome?] }
+ let(:ascii) do
+ %[ __ ___ _ _____ _ ___ \n \\ \\ / / | (_) | __ \\ | | /\\ |__ \\ \n \\ \\ /\\ / /| |__ _ _ _ ___ | |__) | _| |__ _ _ / \\__ _____ ___ ___ _ __ ___ ___ ) |\n \\ \\/ \\/ / | '_ \\| | | | | / __| | _ / | | | '_ \\| | | | / /\\ \\ \\ /\\ / / _ \\ __|/ _ \\| '_ ` _ \\ / _ \\/ / \n \\ /\\ / | | | | |_| | | \\__ \\ | | \\ \\ |_| | |_) | |_| | / ____ \\ V V / __\\__ \\ (_) | | | | | | __/_| \n \\/ \\/ |_| |_|\\__, | |_|___/ |_| \\_\\__,_|_.__/ \\__, | /_/ \\_\\_/\\_/ \\___|___/\\___/|_| |_| |_|\\___(_) \n __/ | __/ | \n |___/ |___/ ]
+ end
+
+ it "monkey patches String to provide a to_ascii method" do
+ sentence.should respond_to(:to_ascii)
+ end
+
+ it "outputs ascii text as expected" do
+ sentence.to_ascii.should eq(ascii)
+ end
+
+ describe "SlideDeck" do
+ let(:deck) { SlideDeck.new(SLIDES) }
+
+ it "will iterate forward through the slides" do
+ deck.next.should eq(SLIDES[0])
+ deck.next.should eq(SLIDES[1])
+ end
+
+ it "will iterate backwards through the slides" do
+ first = deck.next
+ second = deck.next
+ deck.prev.should eq(second)
+ deck.prev.should eq(first)
+ end
+
+ it "will rewind to the begining of the slides" do
+ deck.next; deck.next; deck.next
+ deck.rewind
+ deck.next.should eq(SLIDES.first)
+ end
+
+ it "will not jam nils into the slide deck" do
+ deck.prev
+ deck.next.should_not be_nil
+ end
+
+ it "allows peeking at the next slide without moving forward" do
+ deck.peek.should eq(deck.next)
+ end
+
+ it "will let you fast_foward to the end" do
+ deck.fast_forward
+ deck.peek.should eq(SLIDES.last)
+ end
+ end
+ end
+end
+
+
158 slides.rb
@@ -0,0 +1,158 @@
+clear_screen ="\e[2J\e[100A"
+
+SLIDES = [
+
+ "Why is Ruby Awesome?".to_ascii.red,
+
+ "IRB for one!".to_ascii,
+
+ "A Handy Calculator (4 + 4)".to_ascii,
+
+ "Word counter".to_ascii,
+
+ clear_screen + "Parabolic equations...".to_ascii,
+
+ %Q[
+ For example:
+
+ (-10..10).to_a.map { |x| [x, (x**2) + x - 1] }
+ ],
+
+ clear_screen + "Because of Methods".to_ascii.blue,
+
+ %Q[
+ Example:
+
+ def say_hi
+ puts "hi there"
+ end
+
+ # Note! Methods can end in ! or ?
+ ],
+
+ clear_screen + "Because of Variables".to_ascii.cyan,
+
+ %Q[
+ Examples:
+
+ local_variable (local_hello = 'hi')
+ @instance_variable (@instance_hello = 'hello')
+ $global_variable ($global_hello = 'hello there sir')
+ CONSTANT (CONSTANT_HELLO = 'hello my good man, how are you today?')
+ ],
+
+ "Methods and Variables".to_ascii.colorize(color: :cyan, background: :blue),
+
+ clear_screen + "Data Types".to_ascii.colorize(color: :black, background: :light_white),
+
+ %Q[
+ Examples:
+
+ String # => "Hello there sir" [length, reverse]
+ Symbol # => :immutable_string [swapcase, to_proc]
+ Integer # => 5_000 [public_methods, odd?]
+ Range # => 1..10 [to_a, include?]
+ Boolean # => true [==, !=]
+ Array # => ['a list', 1, true, 'of stuff'] [count, sample, [], last]
+ Hash # => {:key => "Value", :pairs => "Of Data"}, [values, []]
+ ],
+
+ clear_screen + "Control Structures".to_ascii.light_magenta,
+
+ "Conditionally Awesome".to_ascii.yellow,
+
+ %Q[
+ Conditional Examples:
+
+ if true
+ # do some stuff
+ end
+
+ if false
+ # don't do some stuff
+ end
+
+ if condition_a?
+ # some stuff
+ elsif condition_b?
+ # some other stuff
+ else
+ # some totally other stuff
+ end
+
+ unless false
+ # do some stuff
+ end
+
+ unless true
+ # dont do some stuff
+ end
+
+ awesome! if awesome?
+
+ learn_me_some_engrish unless did_that_already?
+ ],
+
+ clear_screen + "Truthyness and Falsyness".to_ascii.green,
+
+ %Q[
+ Examples:
+
+ !!"string" # => true
+ !!5_000 # => true
+ !!true # => true
+ !!"" # => true
+ !!0 # => true
+ !![] # => true
+ !!{} # => true
+ !!false # => false
+ !!nil # => false
+
+ # Note!
+ # Don't use `!!` in your code.
+ # Let ruby handle truthyness and falsyness for you.
+ ],
+
+ clear_screen + "awesome! while true".to_ascii.light_red,
+
+ %Q[
+ Looping Examples:
+
+ while true
+ # do stuff
+ end
+
+ until false
+ # do stuff
+ end
+
+ # NOTE! Like `if` and `unless`, `while` and `until` can "dangle" as well.
+
+ awesome! while true
+ awesome! until false
+ ],
+
+ clear_screen + "Wherefore art thou?".to_ascii.light_red,
+
+ %Q[
+ Using for:
+
+ for i in 0..5 do
+ puts i
+ end
+
+ # NOTE! I literally had to Google how to do this.
+ ],
+
+ "To each his own".to_ascii.light_red,
+
+ %Q[
+ (0..5).each do
+ puts i
+ end
+
+ # NOTE! I did not have to Google how to do this.
+ ]
+
+].freeze
+

0 comments on commit 98964f9

Please sign in to comment.