Saturday, December 21, 2013

Refactoring w/ Cynthia, Frances & REve

Grep-ing is incredibly useful when looking for something in a file you are unfamiliar with
  $ grep -rn "whatever you are looking for" . 
-r means recursively which means your computer will look in a file if it is not there then it will keep looking until there is m=nothing else to look for
n is line number
. the dot at the end means look through everything

git branch -av
   a is all
   v is verbose

git remote add upstream_user https://github.com/user/repo.git

simplecov - ruby gem that reports how much of your code is covered by tests

Add to your Gemfile

group :test, :development do  
  gem 'hpricot'  
  gem 'simplecov', :require => false #code coverage thingy
end

Add to top of tests  test.rb

  # -*- coding: utf-8 -*-
  # Tests designed to run with autotest.
 require 'simplecov'
 SimpleCov.start
  require 'test/unit'
  require 'fileutils' # for saving downloaded XML
  $LOAD_PATH << './lib'
  require 'reve'

cattr_reader so you can read the class level variable in the instance of the class

    module Class #:nodoc:
      def cattr_reader(*syms) #:nodoc:
        syms.flatten.each do |sym|
          next if sym.is_a?(Hash)
          class_eval(<<-EOS, __FILE__, __LINE__)
            unless defined? @@#{sym}
              @@#{sym} = nil
            end

            def self.#{sym}
              @@#{sym}
            end

            def #{sym}
              @@#{sym}
            end
          EOS
        end
      end

      def cattr_writer(*syms) #:nodoc:
        options = syms.last.is_a?(Hash) ? syms.pop : {}
        syms.flatten.each do |sym|
          class_eval(<<-EOS, __FILE__, __LINE__)
            unless defined? @@#{sym}
              @@#{sym} = nil
            end

            def self.#{sym}=(obj)
              @@#{sym} = obj
            end
            #{"
            def #{sym}=(obj)
              @@#{sym} = obj
            end
            " unless options[:instance_writer] == false }
          EOS
        end
      end
      def cattr_accessor(*syms) #:nodoc:
        cattr_reader(*syms)
        cattr_writer(*syms)
      end
    end


No comments:

Post a Comment