るりまサーチ

最速Rubyリファレンスマニュアル検索!
45件ヒット [1-45件を表示] (0.058秒)
トップページ > クエリ:String[x] > クエリ:body[x] > 種類:特異メソッド[x]

別のキーワード

  1. string []=
  2. string []
  3. string slice
  4. string slice!
  5. string gsub

ライブラリ

クラス

モジュール

キーワード

検索結果

CGI.pretty(string, shift = " ") -> String (257.0)

HTML を人間に見やすく整形した文字列を返します。

...

@param string HTML を指定します。

@param shift インデントに使用する文字列を指定します。デフォルトは半角空白二つです。

例:
require "cgi"

print CGI.pretty("<HTML><BODY></BODY></HTML>")
# <HTML>
# <BODY>...
...# </BODY>
# </HTML>

print CGI.pretty("<HTML><BODY></BODY></HTML>", "\t")
# <HTML>
# <BODY>
# </BODY>
# </HTML>...

RubyVM::InstructionSequence.disasm(body) -> String (227.0)

引数 body で指定したオブジェクトから作成した RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字 列に変換して返します。

...引数 body で指定したオブジェクトから作成した
RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字
列に変換して返します。

@param body Proc、Method オブジェクトを指定します。

例1:Proc オブジェクトを指定した場合...
...( 1)
0002 trace 1 ( 2)
0004 putself
0005 putstring "hello, world"
0007 send :puts, 1, nil, 8, <ic:0>
0013 trace 16 (...

RubyVM::InstructionSequence.disassemble(body) -> String (227.0)

引数 body で指定したオブジェクトから作成した RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字 列に変換して返します。

...引数 body で指定したオブジェクトから作成した
RubyVM::InstructionSequence オブジェクトを人間が読める形式の文字
列に変換して返します。

@param body Proc、Method オブジェクトを指定します。

例1:Proc オブジェクトを指定した場合...
...( 1)
0002 trace 1 ( 2)
0004 putself
0005 putstring "hello, world"
0007 send :puts, 1, nil, 8, <ic:0>
0013 trace 16 (...

RubyVM::AbstractSyntaxTree.parse(string) -> RubyVM::AbstractSyntaxTree::Node (127.0)

文字列を抽象構文木にパースし、その木の根ノードを返します。

...文字列を抽象構文木にパースし、その木の根ノードを返します。

@param string パースする対象の Ruby のコードを文字列で指定します。
@param keep_script_lines true を指定すると、 Node#script_lines でノードと関連づけられたソースコ...
...ーを生成します。
@raise SyntaxError string が Ruby のコードとして正しくない場合に発生します。

//emlist[][ruby]{
pp RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
# => (SCOPE@1:0-1:9
# tbl: [:x]
# args: nil
# body:
# (LASGN@1:0-1:9 :x
# (OPCALL...
...IST@1:8-1:9 (LIT@1:8-1:9 2) nil))))
pp RubyVM::AbstractSyntaxTree.parse("x = 1; p(x; y=2", error_tolerant: true)
# => (SCOPE@1:0-1:15
# tbl: [:x, :y]
# args: nil
# body: (BLOCK@1:0-1:15 (LASGN@1:0-1:5 :x (LIT@1:4-1:5 1)) (ERROR@1:7-1:11) (LASGN@1:12-1:15 :y (LIT@1:14-1:15 2))))
//}...

RubyVM::AbstractSyntaxTree.parse(string, keep_script_lines: false, error_tolerant: false, keep_tokens: false) -> RubyVM::AbstractSyntaxTree::Node (127.0)

文字列を抽象構文木にパースし、その木の根ノードを返します。

...文字列を抽象構文木にパースし、その木の根ノードを返します。

@param string パースする対象の Ruby のコードを文字列で指定します。
@param keep_script_lines true を指定すると、 Node#script_lines でノードと関連づけられたソースコ...
...ーを生成します。
@raise SyntaxError string が Ruby のコードとして正しくない場合に発生します。

//emlist[][ruby]{
pp RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
# => (SCOPE@1:0-1:9
# tbl: [:x]
# args: nil
# body:
# (LASGN@1:0-1:9 :x
# (OPCALL...
...IST@1:8-1:9 (LIT@1:8-1:9 2) nil))))
pp RubyVM::AbstractSyntaxTree.parse("x = 1; p(x; y=2", error_tolerant: true)
# => (SCOPE@1:0-1:15
# tbl: [:x, :y]
# args: nil
# body: (BLOCK@1:0-1:15 (LASGN@1:0-1:5 :x (LIT@1:4-1:5 1)) (ERROR@1:7-1:11) (LASGN@1:12-1:15 :y (LIT@1:14-1:15 2))))
//}...

絞り込み条件を変える

RubyVM::AbstractSyntaxTree.parse(string) -> RubyVM::AbstractSyntaxTree::Node (120.0)

文字列を抽象構文木にパースし、その木の根ノードを返します。

...文字列を抽象構文木にパースし、その木の根ノードを返します。

@param string パースする対象の Ruby のコードを文字列で指定します。
@raise SyntaxError string が Ruby のコードとして正しくない場合に発生します。

//emlist[][ruby]{
pp...
...RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
# => (SCOPE@1:0-1:9
# tbl: [:x]
# args: nil
# body:
# (LASGN@1:0-1:9 :x
# (OPCALL@1:4-1:9 (LIT@1:4-1:5 1) :+ (LIST@1:8-1:9 (LIT@1:8-1:9 2) nil))))
//}...

Data.define(*args) -> Class (43.0)

Data クラスに新しいサブクラスを作って、それを返します。

...用できます。

//emlist[例][ruby]{
class HTTPFetcher
Response = Data.define(:body)
NotFound = Data.define

def get(url)
# ダミーの実装
if url == "http://example.com/"
Response.new(body: "Current time is #{Time.now}")
else
NotFound.new
end
end
end

def...
...fetch(url)
fetcher = HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body

in HTTPFetcher::NotFound
:NotFound
end
end

p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFound
//}

@par...
...ブジェクトのクラスを定義するための可変長引数。Symbol または String を指定します。

@return Data のサブクラスを返します。

@raise TypeError 引数に Symbol, String (String に暗黙の型変換が行われるオブジェクトを含む) 以外を指定し...

Data.define(*args) {|subclass| block } -> Class (43.0)

Data クラスに新しいサブクラスを作って、それを返します。

...用できます。

//emlist[例][ruby]{
class HTTPFetcher
Response = Data.define(:body)
NotFound = Data.define

def get(url)
# ダミーの実装
if url == "http://example.com/"
Response.new(body: "Current time is #{Time.now}")
else
NotFound.new
end
end
end

def...
...fetch(url)
fetcher = HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body

in HTTPFetcher::NotFound
:NotFound
end
end

p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFound
//}

@par...
...ブジェクトのクラスを定義するための可変長引数。Symbol または String を指定します。

@return Data のサブクラスを返します。

@raise TypeError 引数に Symbol, String (String に暗黙の型変換が行われるオブジェクトを含む) 以外を指定し...