This file contains 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
module Gosu | |
class Font | |
class << self | |
attr_accessor :factor_stored, :factor_rendered | |
end | |
self.factor_stored = 2 # How much larger is it stored as a font. | |
self.factor_rendered = 0.5 # How much smaller it is rendered. | |
alias_method :original_initialize, :initialize |
This file contains 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
# calls a method many times with different args | |
# sort of an inverted Enumerable#each(&Symbol) | |
module Enumerable | |
def each_method(method_name, object = Kernel, &block) | |
each do |*args| | |
object.send(method_name, *args, &block) | |
end | |
end | |
end |
This file contains 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
# True fibers. WORKS! | |
require 'fiber' | |
class Fibers | |
def initialize | |
@fiber = Fiber.new do | |
10.times do | |
puts "hello" | |
Fiber.yield |
This file contains 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
# Equivalent is: | |
# (year % 4 == 0) and not ((year % 100 == 0) and (year 400 != 0)) | |
def leap_year?(year) | |
(year % 4 == 0) and ((year % 100 != 0) or (year 400 == 0)) | |
end | |
puts "Gimmeh the starting year:" | |
year_start = gets.to_i | |
puts "Gimmeh the end year:" | |
year_end = gets.to_i |
This file contains 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 Integer | |
INT_TO_ROMAN = { | |
1000 => 'M', | |
500 => 'D', | |
100 => 'C', | |
50 => 'L', | |
10 => 'X', | |
5 => 'V', | |
1 => 'I', | |
} |
This file contains 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
module Gosu | |
class Window | |
%w(update draw needs_redraw? needs_cursor? | |
lose_focus button_down button_up).each do |callback| | |
define_method "protected_#{callback}" do |*args| | |
begin | |
# Turn into a boolean result for needs_cursor? etc while we are at it. | |
@_exception ? false : !!send(callback, *args) | |
rescue Exception => e | |
# Exit the message loop naturally, then re-throw |
This file contains 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
### Overriding global customization | |
Pry.config settings apply to all Pry instances, but some values can be overridden for a specific instance. The values that can be overridden are: `input`, `output`, `print`, `exception_handler`, `prompt`, and `hooks`. To override a given value, pass a new value as a hashed option for the method that initiates Pry. | |
Example: Overriding a global default at instantiation | |
```ruby | |
Pry.config.input = File.open("test.rb") | |
# Use a string-io for this specific instance. |
This file contains 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
app_path = __FILE__.chomp(File.extname(__FILE__)) | |
binary_extensions = %w[.bundle .so] | |
binary_extensions.unshift ".#{RUBY_VERSION[0..2]}.so" if defined? RUBY_VERSION | |
found = binary_extensions.any? do |extension| | |
file = "#{app_path}#{extension}" | |
if File.exist? file | |
require file | |
true |
This file contains 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
spooner@Fish:~$ gem install renet-0.1.7.gem | |
Building native extensions. This could take a while... | |
ERROR: Error installing renet-0.1.7.gem: | |
ERROR: Failed to build gem native extension. | |
/home/spooner/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb | |
creating Makefile | |
gcc -I. -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/x86_64-linux -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -fPIC -o unix.o -c unix.c | |
unix.c:19:23: error: enet/enet.h: No such file or directory | |
unix.c:34: error: conflicting types for ‘socklen_t’ |
This file contains 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
spooner@Fish:~/renet_tests$ gem install renet-0.1.12.gem | |
Building native extensions. This could take a while... | |
ERROR: Error installing renet-0.1.12.gem: | |
ERROR: Failed to build gem native extension. | |
/home/spooner/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb | |
creating Makefile | |
gcc -I. -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/x86_64-linux -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -fPIC -o unix.o -c unix.c | |
gcc -I. -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/x86_64-linux -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/home/spooner/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-f |