Programming Ruby : http://ruby-doc.com/docs/ProgrammingRuby/
C:\Users\Hyeseung>ruby -v
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x64-mingw32]
C:\Users\Hyeseung>irb
irb(main):001:0> puts 'hello, world'
hello, world
=> nil
irb(main):002:0> language = 'Ruby'
=> "Ruby"
irb(main):003:0> puts "hello, #{language}"
hello, Ruby
=> nil
irb(main):004:0* language =
irb(main):005:0> 'my Ruby'
=> "my Ruby"
irb(main):006:0> puts "hello, #{language}"
hello, my Ruby
=> nil
irb(main):007:0> 4.class
=> Integer
irb(main):008:0> 4 + 4
=> 8
irb(main):009:0> 8.methods
=> [:bit_length, :digits, :|, :-@, :**, :<=>, :<<, :>>, :<=, :>=, :==, :===, :next, :[], :upto, :chr, :%, :&, :*, :+, :inspect, :-, :/, :size, :succ, :<, :>, :ord, :to_int, :to_s, :to_i, :to_f, :to_r, :numerator, :denominator, :rationalize, :div, :divmod, :fdiv, :coerce, :^, :lcm, :gcdlcm, :gcd, :modulo, :remainder, :abs, :magnitude, :integer?, :floor, :ceil, :round, :truncate, :odd?, :even?, :allbits?, :anybits?, :nobits?, :downto, :times, :pred, :pow, :~, :dup, :+@, :polar, :conjugate, :rect, :eql?, :singleton_method_added, :arg, :quo, :rectangular, :i, :real?, :zero?, :nonzero?, :finite?, :infinite?, :step, :positive?, :negative?, :imaginary, :imag, :to_c, :angle, :phase, :real, :conj, :abs2, :clone, :clamp, :between?, :itself, :yield_self, :then, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :class, :display, :hash, :singleton_class, :singleton_method, :method, :public_send, :define_singleton_method, :public_method, :extend, :to_enum, :enum_for, :=~, :!~, :nil?, :respond_to?, :freeze, :object_id, :send, :__send__, :!, :!=, :__id__, :equal?, :instance_eval, :instance_exec]
irb(main):010:0> 'Hailey'.class
=> String
irb(main):011:0> name = 'Hailey'
=> "Hailey"
irb(main):012:0> name.methods
=> [:unicode_normalize, :unicode_normalize!, :ascii_only?, :unpack, :to_r, :encode, :encode!, :%, :include?, :*, :+, :count, :to_c, :partition, :+@, :-@, :<=>, :<<, :==, :===, :sum, :=~, :next, :[], :casecmp, :casecmp?, :insert, :[]=, :match, :match?, :bytesize, :empty?, :eql?, :succ!, :next!, :upto, :index, :rindex, :replace, :clear, :chr, :getbyte, :setbyte, :scrub!, :scrub, :undump, :byteslice, :freeze, :inspect, :capitalize, :upcase, :dump, :downcase!, :swapcase, :downcase, :hex, :capitalize!, :upcase!, :lines, :length, :size, :codepoints, :succ, :split, :swapcase!, :bytes, :oct, :prepend, :grapheme_clusters, :concat, :start_with?, :reverse, :reverse!, :to_str, :to_sym, :crypt, :ord, :strip, :end_with?, :to_s, :to_i, :to_f, :center, :intern, :gsub, :ljust, :chars, :delete_suffix, :sub, :rstrip, :scan, :chomp, :rjust, :lstrip, :chop!, :delete_prefix, :chop, :sub!, :gsub!, :delete_prefix!, :chomp!, :strip!, :lstrip!, :rstrip!, :squeeze, :delete_suffix!, :tr, :tr_s, :delete, :each_line, :tr!, :tr_s!, :delete!, :squeeze!, :slice, :each_byte, :each_char, :each_codepoint, :each_grapheme_cluster, :b, :slice!, :rpartition, :encoding, :force_encoding, :unpack1, :valid_encoding?, :hash, :unicode_normalized?, :clamp, :between?, :<=, :>=, :>, :<, :dup, :itself, :yield_self, :then, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :class, :clone, :display, :singleton_class, :singleton_method, :method, :public_send, :define_singleton_method, :public_method, :extend, :to_enum, :enum_for, :!~, :nil?, :respond_to?, :object_id, :send, :__send__, :!, :!=, :__id__, :equal?, :instance_eval, :instance_exec]
irb(main):013:0> x = 4
=> 4
irb(main):014:0> x < 5
=> true
irb(main):015:0> true.class
=> TrueClass
irb(main):016:0> x = 4
=> 4
irb(main):017:0> puts 'This appears to be false' unless x == 4
=> nil
irb(main):018:0> 'This appears to be true' if x == 4
=> "This appears to be true"
irb(main):019:-> end
Traceback (most recent call last):
3: from C:/Ruby27-x64/bin/irb.cmd:31:in `<main>'
2: from C:/Ruby27-x64/bin/irb.cmd:31:in `load'
1: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
SyntaxError ((irb):19: syntax error, unexpected `end')
irb(main):020:1* if x == 4
irb(main):021:1* puts 'This appears to be true'
irb(main):022:0> end
This appears to be true
=> nil
irb(main):023:1* unless x==4
irb(main):024:1* puts 'This appears to be false'
irb(main):025:1* else
irb(main):026:1* puts 'This appears to be true'
irb(main):027:0> end
This appears to be true
=> nil
irb(main):028:0>
irb(main):029:0>
irb(main):030:0> i = 0
=> 0
irb(main):031:0> a = ['100', 100.0]
=> ["100", 100.0]
irb(main):032:1* while i < 2
irb(main):033:1* puts a[i].to_i
irb(main):034:1* i=i+1
irb(main):035:0> end
100
100
=> nil
irb(main):036:0>
irb(main):037:0>
irb(main):038:0>
irb(main):039:1* class Song
irb(main):040:2* def initialize(name, artist, duration)
irb(main):041:2* @name = name
irb(main):042:2* @artist = artist
irb(main):043:2* @duration = duration
irb(main):044:1* end
irb(main):045:0> end
=> :initialize
irb(main):046:0>
irb(main):047:0>
irb(main):048:1* class Song
irb(main):049:2* def to_s
irb(main):050:2* "Song: #{@name}--#{@artist} (#{@duration})"
irb(main):051:1* end
irb(main):052:0> end
=> :to_s
irb(main):053:0> aSong = Song.new("Bicylops", "Fleck", 260)
=> #<Song:0x0000018e95062078 @name="Bicylops", @artist="Fleck", @duration=260>
irb(main):054:0> aSong.to_s
=> "Song: Bicylops--Fleck (260)"
irb(main):055:0>
irb(main):056:0>
irb(main):057:0>
'개발 > Ruby On rails' 카테고리의 다른 글
MAC M1 Github blog 깃허브 블로그 만들다가 발생한 Ruby gem 에러 (1) | 2024.01.07 |
---|---|
[Ruby] Ruby 손쉽게 설치하기 (0) | 2021.05.03 |