今天工作:
学习ruby语言:
看光照ruby代码:
学习css:
观看sketchup说明文件:
查找vue框架:
CSS 伪类(Pseudo-classes)
CSS伪类是用来添加一些选择器的特殊效果。
Ruby基础学习:
ruby条件判断:
if condition then code
while condition do code
break、next、redo、retry
Ruby 方法(函数),方法名应以小写字母开头,调用时:method_name 25, 30
#!/usr/bin/ruby
class Customer
def initialize(id, name, addr)
@cust_id=id
@cust_name=name
@cust_addr=addr
end
def display_details()
puts “Customer id #@cust_id”
puts “Customer name #@cust_name”
puts “Customer address #@cust_addr”
end
end
创建对象
cust1=Customer.new(“1”, “John”, “Wisdom Apartments, Ludhiya”)
cust2=Customer.new(“2”, “Poul”, “New Empire road, Khandala”)
调用方法
cust1.display_details()
cust2.display_details()
ruby中变量类型只有$(全局变量)、@(实例变量、@@类变量、大写字母开头(常量)
可变数量的参数
def sample (*test)
puts “参数个数为 #{test.length}”
for i in 0…test.length
puts “参数值为 #{test[i]}”
end
end
sample “Zara”, “6”, “F”
sample “Mac”, “36”, “M”, “MCA”
alias 起别名
alias 方法名 方法名
alias 全局变量 全局变量
undef 取消方法定义
undef bar取消
ruby块
block_name{
statement1
statement2
…
}
使用yield语句调用块,当块名与方法函数名相同时,使用yield调用块k,
test {puts “你在块内”} #块
在两个竖线之间放置一个变量来接受参数
test {|i| puts “你在块 #{i} 内”}
ruby模块(Module)
把方法、类和常量组合在一起的方式
好处:
模块提供了一个命名空间和避免名字冲突。
模块实现了 mixin 装置。
模块与类的不同:
模块不能实例化
模块没有子类
模块只能被另一个模块定义
ruby require语句
require相当于C++ 中的 include
module消除了继承的需要,l提供了mixin装置
module A
def a1
end
def a2
end
end
module B
def b1
end
def b2
end
end
class Sample
include A
include B
def s1
end
end
samp=Sample.new
samp.a1
samp.a2
samp.b1
samp.b2
samp.s1
ruby字符串(string)
单引号字符串
双引号字符串
在双引号字符串中我们可以使用 #{} 井号和大括号来计算表达式的值:
puts “你好 #{name1}, #{name2} 在哪?”
字符串转义字符
ruby数组
创建数组
names = Array.new
设置数组大小
names = Array.new(20)
给数组元素赋值:
names = Array.new(4, “mac”)
puts “#{names}”
公共的数组方法:
ruby 哈希(hash)
哈希的索引叫做“键”
哈希(Hash)是类似 “key” => “value” 这样的键值对集合。
哈希和数组的区别:Hash 的元素没有特定的顺序
创建hash:
months = Hash.new
months = Hash.new( “month” )
哈希内置方法:
公共的哈希方法:
ruby 日期&时间(Date & time)
创建当前的日期和时间:
#!/usr/bin/ruby -w
-- coding: UTF-8 --
time = Time.new
Time 的组件
puts "当前时间 : " + time.inspect
puts time.year # => 日期的年份
puts time.month # => 日期的月份(1 到 12)
puts time.day # => 一个月中的第几天(1 到 31)
puts time.wday # => 一周中的星期几(0 是星期日)
puts time.yday # => 365:一年中的第几天
puts time.hour # => 23:24 小时制
puts time.min # => 59
puts time.sec # => 59
puts time.usec # => 999999:微秒
puts time.zone # => “UTC”:时区名称
ruby 范围(Range):
范围(Range)无处不在:a 到 z、 0 到 9、等等。Ruby 支持范围,并允许我们以不同的方式使用范围:
作为序列的范围
(1…5) #> 1, 2, 3, 4, 5
(1…5) #> 1, 2, 3, 4
(‘a’…‘d’) #==> ‘a’, ‘b’, ‘c’, ‘d’
作为条件的范围
作为间隔的范围
Ruby迭代器
代器(iterator)就是用来重复多次相同的事
each迭代器和collect迭代器
Ruby each迭代器返回数组或哈希的所有元素
collect >= each
Ruby collect迭代器返回集合的所有元素
Ruby文件的输入与输出
puts语句
gets语句
putc 语句可用于依次输出一个字符
print语句
print 语句与 puts 语句类似。唯一的不同在于 puts 语句在输出内容后会跳到下一行,而使用 print 语句时,光标定位在同一行。
打开和关闭文件
aFile = File.new(“filename”, “mode”)
… 处理文件
aFile.close
File.open 方法
文件查询
打开文件前检查文件是否已存在
Ruby 中的目录
file类和方法
File 表示一个连接到普通文件的 stdio 对象。open 为普通文件返回该类的一个实例。
Ruby Dir 类和方法
Dir 是一个表示用于给出操作系统中目录中的文件名的目录流。Dir 类也拥有与目录相关的操作,比如通配符文件名匹配、改变工作目录等。
异常处理:
输出前面加#
变量前面加@
Ruby正则表达式
正则表达式是一种特殊序列的字符,它通过使用有专门语法的模式来匹配或查找字符串集合。
对照ruby程序查看sketchup帮助文件,查看sketchup接口:
model = Sketchup.active_model
entities = model.entities
current = model.selection[0]
sketchup developer 帮助文件
https://www.suapp.me/ruby/Sketchup/Model.html
model abject
Vue全家桶(Vue-cli、Vue-route、vuex)
现在变量cross指向的是什么?
ruby
输出前面加#
变量前面加@
Ruby正则表达式
正则表达式是一种特殊序列的字符,它通过使用有专门语法的模式来匹配或查找字符串集合。
#find_entity_by_persistent_id(ids_or_array) ⇒ Array<Sketchup::Entity, nil>
#name ⇒ Object
The name method retrieves the string name of the model.
#styles ⇒ Object
The styles method retrieves the styles associated with the model.
#utm_to_point(utm) ⇒ Object
The utm_to_point method converts a position given in UTM coordinates to a Point3d in the Model.
.intersect_line_line(line1, line2) ⇒ Geom::Point3d?
The Geom.intersect_line_line computes the intersection of two lines.
#end ⇒ Object
The end method is used to retrieve the Vertex object at the end of the edge.
#length(*args) ⇒ Object
The length method is used to retrieve the length of an edge in current units.
#other_vertex(vertex1) ⇒ Object
The other_vertex method is used to find the opposite vertex given one vertex of the edge.
find_edge.is_a? Sketchup::Edge