View instance_eval_example.rb
1 2 3 4 5 6 7 8 9 10
class Controller
attr_reader :tag
 
def initialize
@tag = "Controller"
@window = Window.new(self)
@window.show
hello
hello_again
end
View app.rb
1 2 3 4 5 6 7 8 9 10
app = UIApplication.sharedApplication
 
NSLog "statusBarHidden #{app.statusBarHidden.inspect rescue nil}" # fails (documented)
NSLog "statusBarHidden? #{app.statusBarHidden?.inspect rescue nil}" # passes (undocumented)
NSLog "idleTimerDisabled #{app.idleTimerDisabled.inspect rescue nil}" # fails (documented)
NSLog "idleTimerDisabled? #{app.idleTimerDisabled?.inspect rescue nil}" # passes (undocumented)
NSLog "networkActivityIndicatorVisible #{app.networkActivityIndicatorVisible.inspect rescue nil}" # fails (documented)
NSLog "networkActivityIndicatorVisible? #{app.networkActivityIndicatorVisible?.inspect rescue nil}" # passes (undocumented)
 
### However:
View alert_self.rb
1 2 3 4 5 6 7 8 9
class Alert
def initialize(title, message, *buttons)
#
# Delegating to self.
#
@alert = UIAlertView.alloc.initWithTitle(title, message:message, delegate:self, cancelButtonTitle:"Cancel", otherButtonTitles:"OK", nil)
@alert.show
self
end
View Rakefile
1 2 3 4 5 6 7 8 9
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require '~/Source/Ruby/Motion/motion_awesome_print/lib/awesome_print'
 
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'hello'
end
View kill.sh
1 2 3
function k() {
kill -9 $(ps ax | grep $1 | grep -v grep | awk '{print $1}')
}
View sort.rb
1 2 3 4 5 6 7 8 9 10
# Plain bubble sort.
def bubble_sort(array)
loop do
swapped = false
(array.size - 1).times do |i|
if array[i] > array[i+1]
array[i], array[i+1] = array[i+1], array[i]
swapped = true
end
end
View console.coffee
1 2 3 4 5 6
window.console or do ->
window.console = {}
for method in [ "log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd" ]
window.console[method] = ->
return
View refactored.rb
1 2 3 4 5 6 7 8 9
# Original
Dir.glob("./commands/*.rb").each do |command|
$commands << command.split("/").last.split('.rb').first
end
 
# Refactored
Dir.glob("./commands/*.rb").each do |command|
$commands << File.basename(command, '.*')
end
View ap30.rb
1 2 3 4 5 6 7 8 9 10
# 0.4.0 TODO
#
# - merge Windows fix
# - merge Stephan's ap/object
# - merge Mongo(?)
# - specs for arbitrary Obj
# - rescue LoadError if in specs if Rails is not installed
# - require unless defined?(::AwesomePrint) (when required from .irbrc)
# - Obj overrides :send
# - Obj overrides :method
View gist:792850
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/env ruby
# Usage:
# $ ./script/railssh
 
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require APP_PATH
Rails.application.require_environment!
 
module Kernel
Something went wrong with that request. Please try again.