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
require "minruby" | |
def evaluate(tree, env) | |
# pp(tree) | |
case tree[0] | |
when "lit" | |
tree[1] | |
when "+" | |
evaluate(tree[1], env) + evaluate(tree[2], env) | |
when "-" |
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
# $ ruby interp.rb test.rb | |
# test.rb | |
# plus_count=0 | |
# x = 1+2+3 | |
# p(plus_count) #=> 2 | |
# x = 1+2+3 | |
# p(plus_count) #=> 4 | |
require "minruby" |
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 A | |
def foo | |
"A" | |
end | |
end | |
class B < A | |
def foo | |
"B" + super | |
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
# ruby 2.7.0preview2 (2019-10-22 master 02aadf1032) [x86_64-darwin18] | |
class Foo | |
private def foo | |
"foo!!" | |
end | |
def bar | |
self.foo | |
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
# Rubyでメソッドと、そうではないもの(式とか)の見分け方 | |
# methodメソッドで取得できたらメソッド | |
method(:p) #=> #<Method: main.p> | |
# ↑とれたのでメソッド | |
method(:for) | |
#=> NameError: undefined method `for' for class `#<Class:#<Object:0x00007fd82d0d22f0>>' | |
# ↑とれないのでメソッドではない |
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
# $ gem i selenium-webdriver | |
require "selenium-webdriver" | |
options = Selenium::WebDriver::Chrome::Options.new | |
options.add_argument('--headless') | |
# headless指定すると普段Chromeで指定しているフォント指定が効かなくなる | |
driver = Selenium::WebDriver.for :chrome, options: options | |
driver.get("https://igarashikuniaki.net/diary/") | |
driver.save_screenshot("ss.png") |
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
## rubyforge | |
$ gem sources -l | |
*** CURRENT SOURCES *** | |
http://gems.rubyforge.org/ | |
$ gem i awesome_print | |
ERROR: While executing gem ... (TypeError) |
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
# enc_test.txt に 日本語 を1行書いておく | |
File.open("enc_test.txt") do |f| | |
puts out_str = f.each_line.first | |
puts out_str.encoding | |
end | |
puts in_str = "中の日本語" | |
puts in_str.encoding |
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
@interface ImageUploader : NSObject { | |
NSData *theImage; | |
} | |
@property (retain) NSData *theImage; | |
- (void) syncUpload:(NSData *) uploadImage; | |
@end | |
#import "ImageUploader.h" |
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 Hoimirable | |
def hoimi | |
@hp = [@hp + 20, @max_hp].min | |
end | |
end | |
class Sumaltria | |
include Hoimirable | |
end |