Class: RbsGoose::IO::TypedRuby

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_goose/io/typed_ruby.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruby:, rbs:) ⇒ TypedRuby

Returns a new instance of TypedRuby.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
# File 'lib/rbs_goose/io/typed_ruby.rb', line 18

def initialize(ruby:, rbs:)
  raise ArgumentError, 'ruby must have ".rb" extension' unless ruby.type == :ruby
  raise ArgumentError, 'rbs must have ".rbs" extension' if !rbs.nil? && rbs.type != :rbs

  @ruby = ruby
  @rbs = rbs
end

Instance Attribute Details

#rbsObject (readonly)

Returns the value of attribute rbs.



30
31
32
# File 'lib/rbs_goose/io/typed_ruby.rb', line 30

def rbs
  @rbs
end

#rubyObject (readonly)

Returns the value of attribute ruby.



30
31
32
# File 'lib/rbs_goose/io/typed_ruby.rb', line 30

def ruby
  @ruby
end

Class Method Details

.from_path(ruby_path:, rbs_path:, base_path:) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/rbs_goose/io/typed_ruby.rb', line 7

def from_path(ruby_path:, rbs_path:, base_path:)
  ruby = File.new(path: ruby_path, base_path:)
  rbs = begin
    File.new(path: rbs_path, base_path:)
  rescue StandardError
    nil
  end
  new(ruby:, rbs:)
end

Instance Method Details

#to_sObject



26
27
28
# File 'lib/rbs_goose/io/typed_ruby.rb', line 26

def to_s
  rbs.nil? ? ruby.to_s : "#{ruby}\n#{rbs}"
end