This file contains hidden or 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
| require 'yaml' | |
| state = DATA.read | |
| state = (state.empty?) ? [] : YAML::load(state) | |
| state << 1 | |
| puts state.inspect | |
| code = File.new(__FILE__).readlines | |
| code = code[0..(code.find_index{ |x| /\A__END__\s*\z/ =~ x })].join("") << "\n" << YAML::dump(state) |
This file contains hidden or 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
| static VALUE | |
| boot_defclass(const char *name, VALUE super) | |
| { | |
| extern st_table *rb_class_tbl; | |
| VALUE obj = rb_class_boot(super); | |
| ID id = rb_intern(name); | |
| rb_name_class(obj, id); | |
| st_add_direct(rb_class_tbl, id, obj); | |
| rb_const_set((rb_cObject ? rb_cObject : obj), id, obj); |
This file contains hidden or 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 Employee | |
| attr_accessor :first_name | |
| attr_accessor :last_name | |
| attr_accessor :monthly_sales | |
| def to_s | |
| "#{@first_name} #{@last_name}: #{@monthly_sales}" | |
| end | |
| end |
This file contains hidden or 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 Employee | |
| attr_accessor :first_name | |
| attr_accessor :last_name | |
| attr_accessor :monthly_sales | |
| include Comparable | |
| # 月間売上高で社員をソート | |
| def <=>(other_employee) | |
| other_employee.monthly_sales <=> @monthly_sales | |
| end |
This file contains hidden or 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
| # ランダム数 最小-最大 | |
| def range_rand(min,max) | |
| min + rand(max-min) | |
| end | |
| # ランダム名前 | |
| $names = File.new('names.txt', 'r').readlines.map {|line| line.chomp} | |
| def rand_name | |
| $names[rand($names.length)] | |
| end |
This file contains hidden or 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
| # ソート前 | |
| puts employees.inspect | |
| # ソート後 | |
| puts employees.sort.inspect | |
| # ※ご注意:これはランダムデータなので毎回結果がランダムとなります。 | |
| # [Alec Earl: 3030, Jayce Moises: 8373, Ronald Cornelius: 6653] | |
| # [Jayce Moises: 8373, Ronald Cornelius: 6653, Alec Earl: 3030] |
This file contains hidden or 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 Employee | |
| attr_accessor :first_name | |
| attr_accessor :last_name | |
| attr_accessor :monthly_sales | |
| include Comparable | |
| # 月間売上高で社員をソート | |
| def <=>(other_employee) | |
| other_employee.monthly_sales <=> @monthly_sales | |
| end |
This file contains hidden or 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
| Aaron | |
| Abdiel | |
| Abdullah | |
| Abel | |
| Abraham | |
| Abram | |
| Adam | |
| Adan | |
| Addison | |
| Aden |
This file contains hidden or 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
| irb(main):001:0> puts RUBY_VERSION + " " + RUBY_PLATFORM + " " + RUBY_PATCHLEVEL.to_s | |
| 1.9.2 x86_64-darwin10.8.0 290 | |
| => nil | |
| irb(main):002:0> 12345678987654321.class | |
| => Fixnum | |
| irb(main):001:0> puts RUBY_VERSION + " " + RUBY_PLATFORM + " " + RUBY_PATCHLEVEL.to_s | |
| 1.9.4 i686-linux -1 | |
| => nil | |
| irb(main):002:0> 12345678987654321.class |
This file contains hidden or 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
| include ObjectSpace | |
| class DestructorExample | |
| def initialize(name) | |
| define_finalizer self, proc { |id| puts "Instance #{name} Destroyed!" } | |
| end | |
| end | |
| define_finalizer DestructorExample, proc { |id| puts "Class Desroyed!" } |