Created
June 16, 2017 07:06
-
-
Save kririae/aaa64524f1f4b5a9c29d63d7f123bdfa to your computer and use it in GitHub Desktop.
ruby
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 | |
*.rbc | |
/.config | |
/coverage/ | |
/InstalledFiles | |
/pkg/ | |
/spec/reports/ | |
/spec/examples.txt | |
/test/tmp/ | |
/test/version_tmp/ | |
/tmp/ | |
# Used by dotenv library to load environment variables. | |
# .env | |
## Specific to RubyMotion: | |
.dat* | |
.repl_history | |
build/ | |
*.bridgesupport | |
build-iPhoneOS/ | |
build-iPhoneSimulator/ | |
## Specific to RubyMotion (use of CocoaPods): | |
# | |
# We recommend against adding the Pods directory to your .gitignore. However | |
# you should judge for yourself, the pros and cons are mentioned at: | |
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | |
# | |
# vendor/Pods/ | |
## Documentation cache and generated files: | |
/.yardoc/ | |
/_yardoc/ | |
/doc/ | |
/rdoc/ | |
## Environment normalization: | |
/.bundle/ | |
/vendor/bundle | |
/lib/bundler/man/ | |
# for a library or gem, you might want to ignore these files since the code is | |
# intended to run in multiple environments; otherwise, check them in: | |
# Gemfile.lock | |
# .ruby-version | |
# .ruby-gemset | |
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | |
.rvmrc |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="RUBY_MODULE" version="4"> | |
<component name="ModuleRunConfigurationManager"> | |
<shared /> | |
<local /> | |
</component> | |
<component name="NewModuleRootManager"> | |
<content url="file://$MODULE_DIR$" /> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
</component> | |
</module> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.3.3-p222" project-jdk-type="RUBY_SDK" /> | |
</project> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/.idea/LEARNING_RUBY.iml" filepath="$PROJECT_DIR$/.idea/LEARNING_RUBY.iml" /> | |
</modules> | |
</component> | |
</project> |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ChangeListManager"> | |
<option name="TRACKING_ENABLED" value="true" /> | |
<option name="SHOW_DIALOG" value="false" /> | |
<option name="HIGHLIGHT_CONFLICTS" value="true" /> | |
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> | |
<option name="LAST_RESOLUTION" value="IGNORE" /> | |
</component> | |
<component name="PropertiesComponent"> | |
<property name="settings.editor.selected.configurable" value="configurable.group.appearance" /> | |
</component> | |
<component name="ShelveChangesManager" show_recycled="false"> | |
<option name="remove_strategy" value="false" /> | |
</component> | |
<component name="TaskManager"> | |
<task active="true" id="Default" summary="Default task"> | |
<created>1497596635287</created> | |
<option name="number" value="Default" /> | |
<option name="presentableId" value="Default" /> | |
<updated>1497596635287</updated> | |
</task> | |
<servers /> | |
</component> | |
<component name="VcsContentAnnotationSettings"> | |
<option name="myLimit" value="2678400000" /> | |
</component> | |
<component name="XDebuggerManager"> | |
<breakpoint-manager /> | |
<watches-manager /> | |
</component> | |
</project> |
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
#!/usr/bin/ruby -w | |
#coding=utf-8 | |
#我是注释 请忽略我 | |
puts "这是主程序<<" | |
BEGIN{ | |
puts "这是初始化程序" | |
} | |
END{ | |
puts "停止ruby程序" | |
} | |
=begin | |
这也是注释 | |
请忽略这个注释 | |
=end | |
a = 5 | |
puts "#{a}" | |
puts 'using #{a}' | |
puts "using \\" | |
=begin | |
这里注意单引号和双引号 | |
单引号不可替换,但是可以转义 | |
双引号既可以替换也可以转义 | |
序列#{expr} | |
=end | |
=begin | |
\n : 换行 | |
\r : 回车 | |
\f : 换页 | |
\b : 退格 | |
\a : 报警 | |
\e : 转义 | |
\s : 空格 | |
\nnn : 八进制 | |
\xnn : 十六进制 | |
\cx,\C-x 某emacs | |
\M-x | |
\M-\C-x | |
\x | |
=end | |
array = ['kino1z','kino2z','kino3z','kino4z','kino5z','kino6z','kino7z',] | |
array.each do |i| | |
puts i | |
end | |
puts array.size,array.length | |
array2 = Array.new(10,'kino3z') | |
puts "#{array2}" | |
array3 = Array.new(10) { |i| i = "kino#{i}z" } | |
puts "#{array3}" |
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
#!/usr/bin/env ruby -w | |
#coding=utf-8 | |
#author : kino3z | |
#touhou.studio | |
#start | |
=begin | |
result = 20*40*80 | |
puts result | |
puts "#{result}" | |
puts "#{20*40*80}" | |
(10...15).each do |n| | |
puts n | |
end | |
class KINO3Z | |
end | |
局部变量:小写或者_开头 | |
实例变量:@开头 | |
类变量:@@开头 | |
全局变量:$开头 | |
class A | |
@@number_a = 0 | |
@bumber_b = 1 | |
end | |
class B | |
def initialize(m,n,h) | |
@b_m = m | |
@b_n = n | |
@b_h = h | |
end | |
end | |
class Sample | |
def function | |
puts "kino3z" | |
end | |
end | |
object = Sample.new | |
object.function | |
class Customer | |
@@no_of_customers = 0 | |
def initialize(id,name,addr) | |
@cust_id = id | |
@cust_name = name | |
@cust_addr = addr | |
@@no_of_customers+=1 | |
end | |
def display_details | |
puts "#{@cust_id}" | |
puts "#{@cust_name}" | |
puts "#{@cust_addr}" | |
end | |
def output | |
puts @@no_of_customers | |
end | |
end | |
customer = Customer.new(0,'reimu','gensokyo') | |
cust2 = Customer.new(1,'marisa','gensokyo') | |
cust2.output | |
#do you mean太亲切了 | |
=end | |
=begin | |
$global = 10 | |
class Class1 | |
def print_global | |
puts "全局变量输出:#{$global}" | |
end | |
end | |
c = Class1.new | |
c.print_global | |
puts __FILE__ | |
puts __LINE__ | |
=end | |
$a = 10 | |
$b = 20 | |
puts $a+$b | |
puts $a*$b | |
puts $a/$b | |
puts "#{$a%$b}" | |
puts $a**$b | |
puts $a === $b | |
puts $a == $b | |
#多了个联合比较运算符 | |
a = 1 | |
b = 1 | |
puts a <=> b | |
b = 2 | |
puts a <=> b | |
a = 3 | |
puts a<=>b | |
#.eql? 判断类型和值 | |
##.equal? | |
#= | |
#+= | |
#-= | |
#*= | |
#%= | |
#**= | |
#可以并行赋值 | |
#例如 | |
a , b ,c = 1,2,3 | |
a,b = b,c | |
#位运算符 | |
# | |
puts ~a | |
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
MIT License | |
Copyright (c) 2017 Kino3z | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment